Skip to content

fix: preserve the source Zarr dtype in from_array - #4335

Merged
d-v-b merged 5 commits into
zarr-developers:mainfrom
d-v-b:codex/require-array-native-dtypes
Sep 10, 2026
Merged

d-v-b merged 5 commits into
zarr-developers:mainfrom
d-v-b:codex/require-array-native-dtypes

Conversation

@d-v-b

@d-v-b d-v-b commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This AI-authored PR ensures that from_array uses the Zarr data type object, when available, instead of the numpy-like data type exposed by array.dtype, which ensures that data types like vlen-bytes have their data type preserved via from_array.

🤖 AI text below 🤖

zarr.from_array({}, data=source) fails when source is a variable-length bytes array. It passes the source's NumPy object dtype to array creation, losing the complete Zarr dtype already available in the source metadata. Inferring a storage type from object then raises ValueError because it is ambiguous.

Preserve the source's explicit Zarr dtype when creating the copy. Array-like inputs continue to use their native dtype.

A parametrized test covers all 22 registered dtype examples in formats 2 and 3, checking dtype preservation and data when copying and reopening. Before the fix, both variable-length bytes cases failed.

Validation: 1,152 from_array tests passed, 720 unsupported format-2 sharding combinations skipped. All repository commit checks passed.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.34%. Comparing base (3203018) to head (eded2e6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4335      +/-   ##
==========================================
+ Coverage   94.31%   94.34%   +0.02%     
==========================================
  Files          92       92              
  Lines       12935    12935              
==========================================
+ Hits        12200    12203       +3     
+ Misses        735      732       -3     
Files with missing lines Coverage Δ
src/zarr/core/array.py 98.08% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/zarr/core/group.py Outdated
@d-v-b d-v-b changed the title fix: preserve dtype information when copying and requiring arrays fix: preserve the source Zarr dtype in from_array Sep 10, 2026
@d-v-b
d-v-b marked this pull request as ready for review September 10, 2026 10:48
@d-v-b

d-v-b commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

simple bugfix, so i'm self-merging

@d-v-b
d-v-b merged commit 7899082 into zarr-developers:main Sep 10, 2026
39 checks passed
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.

1 participant