Skip to content

Conversation

lhao03
Copy link
Contributor

@lhao03 lhao03 commented Aug 13, 2025

When creating an array with data, the docs incorrectly said you could provide the dtype and shape as long as it matched the data's, but when you try to set all three parameters, an error is thrown.

Python 3.11.11 (main, Mar 17 2025, 19:26:36) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zarr
>>> from zarr.storage import LocalStore
>>> store = LocalStore("test")
>>> a = zarr.create_group(store=store)
>>> import numpy as np
>>> b = np.array([1,2,3])
>>> a.create_array(data=b, dtype=b.dtype, shape=b.shape, name="array")
...
    raise ValueError(msg)
ValueError: The data parameter was used, but the shape parameter was also used. This is an error. Either use the data parameter, or the shape parameter, but not both.

Docs for dtype, shape and data parameter are updated based on the behaviour here:

else:
if shape is not None:
msg = (
"The data parameter was used, but the shape parameter was also "
"used. This is an error. Either use the data parameter, or the shape parameter, "
"but not both."
)
raise ValueError(msg)
shape_out = data.shape
if dtype is not None:
msg = (
"The data parameter was used, but the dtype parameter was also "
"used. This is an error. Either use the data parameter, or the dtype parameter, "
"but not both."
)

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label Aug 13, 2025
@d-v-b
Copy link
Contributor

d-v-b commented Aug 14, 2025

When creating an array with data, the docs incorrectly said you could provide the dtype and shape as long as it matched the data's, but when you try to set all three parameters, an error is thrown.

Thank you for this PR! I agree that updating the docstrings is a good fix here.

@d-v-b d-v-b merged commit 2271067 into zarr-developers:main Aug 14, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs release notes Automatically applied to PRs which haven't added release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants