Skip to content
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

Unexpected Vectorized Indexing Setting Behavior #2469

Open
ilan-gold opened this issue Nov 6, 2024 · 1 comment · May be fixed by #2512
Open

Unexpected Vectorized Indexing Setting Behavior #2469

ilan-gold opened this issue Nov 6, 2024 · 1 comment · May be fixed by #2512
Labels
bug Potential issues with the zarr-python library

Comments

@ilan-gold
Copy link

ilan-gold commented Nov 6, 2024

Zarr version

v3.0.0-beta.1 (main)

Numcodecs version

0.13.0

Python Version

3.12

Operating System

Mac

Installation

uv from repo

Description

I think this is vectorized indexing...in any case I think that the following example should error since arr[:][[np.array([1, 2]), np.array([1, 2])]] is 1d but it allows storing a 2d

Steps to reproduce

import tempfile
import numpy as np
import zarr
from zarr.storage import LocalStore

shape = (4, 4)
chunks = (2, 2)
fill_value = 32767

tmp = tempfile.TemporaryDirectory()
arr = zarr.create(
    shape,
    store=LocalStore(root=tmp.name, mode="w"),
    chunks=chunks,
    dtype=np.int16,
    fill_value=fill_value,
    codecs=[zarr.codecs.BytesCodec(), zarr.codecs.BloscCodec()],
)

arr[np.array([1, 2]), np.array([1, 2])] = np.array([[-1, -2], [-3, -4]])
print(arr[:])

gives

[[32767 32767 32767 32767]
 [32767    -1 32767 32767]
 [32767 32767    -2 32767]
 [32767 32767 32767 32767]]

which I would not expect - I would probably expect this to error.

Additional output

No response

@ilan-gold ilan-gold added the bug Potential issues with the zarr-python library label Nov 6, 2024
@dcherian
Copy link
Contributor

dcherian commented Nov 22, 2024

I think this is vectorized indexing.

The nice thing about Zarr is that it provides .oindex and .vindex and set_orthogonal_selection and set_coordinate_selection to be explicit about such things :)


I agree that this should raise an error

Numpy does raise: ValueError: shape mismatch: value array of shape (2,2) could not be broadcast to indexing result of shape (2,)

dcherian added a commit to dcherian/zarr-python that referenced this issue Nov 22, 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