Skip to content

[v3] Accessing data with bools in square bracket notation #1963

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

Closed
brokkoli71 opened this issue Jun 12, 2024 · 1 comment · Fixed by #1968
Closed

[v3] Accessing data with bools in square bracket notation #1963

brokkoli71 opened this issue Jun 12, 2024 · 1 comment · Fixed by #1968
Labels
bug Potential issues with the zarr-python library
Milestone

Comments

@brokkoli71
Copy link
Member

brokkoli71 commented Jun 12, 2024

Zarr version

v3

Numcodecs version

0.12.1

Python Version

3.12

Operating System

Linux

Description

ix = np.random.binomial(1, 0.6, size=z.shape[0]).astype(bool)
print(z[ix])

will result in IndexError( "unsupported selection item for basic indexing; expected integer or slice, got <class 'numpy.ndarray'>)

while z.get_orthogonal_selection(ix) works.

I suppose the problem is within Array.__getitem__

Steps to reproduce

data = np.arange(10)
z = Array.create(
            StorePath(MemoryStore(mode="w")),
            shape=data.shape,
            chunk_shape=(2,),
            dtype=data.dtype,
            )
z[:] = data
ix = np.random.binomial(1, 0.6, size=z.shape[0]).astype(bool)
print(z.get_orthogonal_selection(ix)) #works
print(z[ix]) #fails

Additional output

No response

@brokkoli71 brokkoli71 added the bug Potential issues with the zarr-python library label Jun 12, 2024
@brokkoli71
Copy link
Member Author

Maybe this is expected behavior? as one should always use z.oindex[ix] for orthogonal selection? But then I do not understand why Array.__getitem__ would check for is_pure_orthogonal_indexing

@brokkoli71 brokkoli71 changed the title [v3] Accessing data with square bracket notation via orthogonal selection fails [v3] Accessing data with square bracket notation via mask selection fails Jun 17, 2024
@brokkoli71 brokkoli71 changed the title [v3] Accessing data with square bracket notation via mask selection fails [v3] Accessing data with bools in square bracket notation Jun 17, 2024
@jhamman jhamman added the V3 label Jun 18, 2024
@jhamman jhamman added this to the 3.0.0 milestone Jun 18, 2024
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

Successfully merging a pull request may close this issue.

2 participants