Skip to content

(bug): get_block_selection semantics #2971

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

Open
ilan-gold opened this issue Apr 8, 2025 · 1 comment
Open

(bug): get_block_selection semantics #2971

ilan-gold opened this issue Apr 8, 2025 · 1 comment
Labels
bug Potential issues with the zarr-python library

Comments

@ilan-gold
Copy link
Contributor

Zarr version

v3.0.6

Numcodecs version

0.15.1

Python Version

3.12

Operating System

Linux/Max

Installation

uv

Description

The below, based on https://zarr.readthedocs.io/en/latest/user-guide/arrays.html#block-indexing, would make me think that (0,5) should refer to a chunk not a shard, but the reverse is true judging by the out-of-bounds error (similarly, z.get_block_selection((0, 4)).shape gives (200,200)).

Steps to reproduce

import zarr

z = zarr.create_array('data/test.zarr', shape=(1000, 1000), shards=(200, 200), chunks=(100,100), dtype="uint8")
z.get_block_selection((0, 5))
---------------------------------------------------------------------------
BoundsCheckError                          Traceback (most recent call last)
Cell In[4], line 1
----> 1 z.get_block_selection((0, 5))

File /mnt/volume/zarr_benchmarks/venv/lib/python3.12/site-packages/zarr/_compat.py:43, in _deprecate_positional_args.<locals>._inner_deprecate_positional_args.<locals>.inner_f(*args, **kwargs)
     41 extra_args = len(args) - len(all_args)
     42 if extra_args <= 0:
---> 43     return f(*args, **kwargs)
     45 # extra_args > 0
     46 args_msg = [
     47     f"{name}={arg}"
     48     for name, arg in zip(kwonly_args[:extra_args], args[-extra_args:], strict=False)
     49 ]

File /mnt/volume/zarr_benchmarks/venv/lib/python3.12/site-packages/zarr/core/array.py:3426, in Array.get_block_selection(self, selection, out, fields, prototype)
   3424 if prototype is None:
   3425     prototype = default_buffer_prototype()
-> 3426 indexer = BlockIndexer(selection, self.shape, self.metadata.chunk_grid)
   3427 return sync(
   3428     self._async_array._get_selection(
   3429         indexer=indexer, out=out, fields=fields, prototype=prototype
   3430     )
   3431 )

File /mnt/volume/zarr_benchmarks/venv/lib/python3.12/site-packages/zarr/core/indexing.py:1026, in BlockIndexer.__init__(self, selection, shape, chunk_grid)
   1023     dim_indexers.append(dim_indexer)
   1025     if start >= dim_len or start < 0:
-> 1026         raise BoundsCheckError(dim_len)
   1028 shape = tuple(s.nitems for s in dim_indexers)
   1030 object.__setattr__(self, "dim_indexers", dim_indexers)

BoundsCheckError: 1000

Additional output

No response

@ilan-gold ilan-gold added the bug Potential issues with the zarr-python library label Apr 8, 2025
@ilan-gold
Copy link
Contributor Author

@LDeakin has informed me that this changed with #2463 so maybe just updating the docs at https://zarr.readthedocs.io/en/latest/user-guide/arrays.html#block-indexing would be nice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Potential issues with the zarr-python library
Projects
None yet
Development

No branches or pull requests

1 participant