-
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shape and chunks accept float values when creating an array #2530
Comments
Thanks for the bug report; we are working on version 3 of Shape fails as expected: >>> zarr.ones((10, 10.0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/bennettd/.pyenv/versions/3.11.9/lib/python3.11/site-packages/zarr/api/synchronous.py", line 264, in ones
return Array(sync(async_api.ones(shape, **kwargs)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bennettd/.pyenv/versions/3.11.9/lib/python3.11/site-packages/zarr/core/sync.py", line 141, in sync
raise return_result
File "/Users/bennettd/.pyenv/versions/3.11.9/lib/python3.11/site-packages/zarr/core/sync.py", line 100, in _runner
return await coro
^^^^^^^^^^
File "/Users/bennettd/.pyenv/versions/3.11.9/lib/python3.11/site-packages/zarr/api/asynchronous.py", line 1037, in ones
return await create(shape=shape, fill_value=1, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bennettd/.pyenv/versions/3.11.9/lib/python3.11/site-packages/zarr/api/asynchronous.py", line 907, in create
return await AsyncArray.create(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bennettd/.pyenv/versions/3.11.9/lib/python3.11/site-packages/zarr/core/array.py", line 458, in create
shape = parse_shapelike(shape)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/bennettd/.pyenv/versions/3.11.9/lib/python3.11/site-packages/zarr/core/common.py", line 145, in parse_shapelike
raise TypeError(msg)
TypeError: Expected an iterable of integers. Got (10, 10.0) instead. But we do accept a float for >>> zarr.ones((10,10), chunks=(2, 2.0))
<Array memory://4409673920 shape=(10, 10) dtype=float64> |
Thanks for the reply @d-v-b! I'd be happy to submit a pull request for the chunks following the way the shape input is parsed. |
yes that sounds like the right direction. |
@d-v-b I thought we were supporting verseion 2 for (at least) six months after release of version 3? So I think it would be reasonable to fix this in the version 2 branch, and I'd be happy to review a PR to version 2 and do a bugfix release. |
@dstansby that makes sense! In that case we should fix 2.x and 3.x |
My PR for the main branch has been merged. Should I submit another PR for the v2 branch before closing this issue? |
A PR to the v2 branch would be great - I would say that instead of raising an error, we should raise a warning on the v2 branch because an error would technically be a breaking change. |
Zarr version
v2.18.3
Numcodecs version
v0.12.1
Python Version
v3.11.2
Operating System
Linux
Installation
Using pip into virtual environment
Description
When you create a new array (e.g. using
zarr.zeros
), the tuples for shape and chunks can contain float values.The values after the decimal point are trimmed without a warning.
Is this the intended behavior?
I would expect
zarr-python
to raise an exception or at least a warning.Steps to reproduce
As you can see from the output the float values are trimmed without warning:
Additional output
No response
The text was updated successfully, but these errors were encountered: