Skip to content

fix: preserve empty ND array shape in JSON - #84

Merged
caniko merged 3 commits into
trunkfrom
fix/empty-nd-json-and-pydantic-213
Aug 21, 2026
Merged

caniko merged 3 commits into
trunkfrom
fix/empty-nd-json-and-pydantic-213

Conversation

@caniko

@caniko caniko commented Aug 20, 2026

Copy link
Copy Markdown
Owner

9.1.0. Empty ND arrays keep their shape through JSON, and pydantic 2.13 installs.

np.empty((0, 2)).tolist() is [], so a 2D empty array came back as 1D. The default serializer now always writes shape, and load reshapes from it. Payloads without shape still work for non-empty arrays.

Also:

  • pydantic>=2.12.5,<3 (locked 2.13.4)
  • numpy lock 2.5.2 (>=2.3.5,<3 was already on PyPI 9.0.2)

Fixes #63
Closes #72

tolist() drops rank when the leading axis is 0, so (0, 2) came back as 1D.
Always emit shape and reshape on load. pydantic 2.13 is allowed; 2.12 still
installs. Lock numpy 2.5.2.

Fixes #63
Closes #72

@caniko caniko left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

One validation issue remains before merge.

Comment thread src/pydantic_numpy/helper/validation.py Resolved
@caniko
caniko merged commit cbd5cb6 into trunk Aug 21, 2026
2 checks passed
@caniko
caniko deleted the fix/empty-nd-json-and-pydantic-213 branch August 21, 2026 11:55
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.

Relax NumPy dependency to allow newer 2.x releases Serialization / Deserialization error for empty arrays with dim>1

1 participant