Skip to content

FIX Preserve the shape of empty object arrays - #558

Open
ktz03 wants to merge 2 commits into
skops-dev:mainfrom
ktz03:fix/empty-object-array-shape
Open

ktz03 wants to merge 2 commits into
skops-dev:mainfrom
ktz03:fix/empty-object-array-shape

Conversation

@ktz03

@ktz03 ktz03 commented Oct 19, 2026

Copy link
Copy Markdown

Reference Issues/PRs

No linked issue.

What does this implement/fix? Explain your changes.

Preserve the recorded shape when loading an empty NumPy object array. For example:

import numpy as np
from skops.io import dumps, loads

arr = np.empty((0, 3), dtype=object)
print(loads(dumps(arr)).shape)  # (0,) before; (0, 3) after

Reconstructing the nested list loses dimensions after the first zero-length axis. Allocate empty arrays using the already stored shape; keep nonempty reconstruction, the file format and the trust policy unchanged. Add regression coverage for bytes and file round trips, zero-length axes in different positions, and working empty/nonempty controls.

Validation on Windows CPU with Python 3.12.14, NumPy 2.5.4 and scikit-learn 1.9.1:

  • The same 14 new cases fail 6 / pass 8 on the original implementation and all pass after the fix.
  • Complete skops/io suite, including doctests, audit and old-protocol tests: 1,108 passed, 66 skipped, 1 existing XPASS. The original implementation has the six failures above; the skips and XPASS remain the same. The skips are optional third-party estimators and one empty parameter set.
  • All official pre-commit run --all-files --show-diff-on-failure hooks pass, including Ruff and pyrefly.
  • The wheel builds successfully, all 48 packaged Python files match the source, and a separate wheel installation passes the public array/container round-trip checks.

Any other comments?

No protocol bump is needed. The full repository suite, optional external estimators, other operating systems and the official Python/dependency matrix were not tested.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow fix has appropriate regression coverage and no unresolved review findings.

No open issues 🎉

What changed in this PR

Preserves the recorded shape when loading empty NumPy object arrays without changing nonempty reconstruction.

Changes:

  • Allocates empty object arrays using their stored shape.
  • Adds 14 regression cases covering bytes/file round trips and empty/nonempty controls.
  • Documents the fix in the changelog.
File Description
skops/​io/​tests/​test_persist.py Adds shape, dtype, and value round-trip checks.
skops/​io/​_numpy.py Restores empty arrays using the recorded shape.
docs/​changes.rst Documents preserved empty-array dimensions.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants