-
-
Notifications
You must be signed in to change notification settings - Fork 329
Request for fancy indexing #657
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
Comments
Advanced indexing is covered in these docs. That said, we wound up not adding these to |
Thanks @jakirkham!
The problem is that NumPy itself has not, at least not yet, so in order for napari to support this we would have to implement different code for different array libraries. Fancy indexing is standard NumPy behaviour and it seems to me that, since it's already implemented, it should be straightforward to detect whether a tuple of arrays is given, and do Note: I do think the case of mixing slices and arrays is confusing, but that implementation could be skipped for now? ie one can strictly increase the number of supported use cases without having to implement a whole stack of new functionality? |
@zarr-developers/core-devs, would be good to hear from people on whether this change sounds reasonable |
I think it would be reasonable to copy NumPy's behavior for fancy indexing.
It is indeed unintuitive, but not hard to copy if you explicitly use the
same rules.
…On Tue, Mar 2, 2021 at 4:31 PM jakirkham ***@***.***> wrote:
@zarr-developers/core-devs
<https://github.com/orgs/zarr-developers/teams/core-devs>, would be good
to hear from people on whether this change sounds reasonable
—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
<#657 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJJFVTAZDCIKSHGTDOJM3LTBV7PPANCNFSM4UAFHSKA>
.
|
Would this constitute a breaking change? Or just something that used to error that now would work? If the latter, I am 👍. People don't have to use it if they find it confusing! |
I think it currently errors |
For context this came up as it is handy in duck-typed code that may handle many NumPy-like things (like Dask, Zarr, etc.). |
To be clear, Dask is not yet current consistent with NumPy, either, but that could be fixed: dask/dask#7313. Thus I would advise caution before relying on this feature :) |
^ @jni |
We're ok, we don't do the crazy combining stuff. 😜 I think! 😅 Thanks @shoyer, we'll try to submit a PR soon! |
Addresses zarr-developers#657 This matches NumPy behaviour in that basic, boolean, and vectorized integer (fancy) indexing are all accessible from `__{get,set}item__`. Users still have access to all the indexing methods if they want to be sure to use only basic indexing (integer + slices).
Addresses zarr-developers#657 This matches NumPy behaviour in that basic, boolean, and vectorized integer (fancy) indexing are all accessible from `__{get,set}item__`. Users still have access to all the indexing methods if they want to be sure to use only basic indexing (integer + slices).
Addresses zarr-developers#657 This matches NumPy behaviour in that basic, boolean, and vectorized integer (fancy) indexing are all accessible from `__{get,set}item__`. Users still have access to all the indexing methods if they want to be sure to use only basic indexing (integer + slices).
Addresses zarr-developers#657 This matches NumPy behaviour in that basic, boolean, and vectorized integer (fancy) indexing are all accessible from `__{get,set}item__`. Users still have access to all the indexing methods if they want to be sure to use only basic indexing (integer + slices).
Addresses zarr-developers#657 This matches NumPy behaviour in that basic, boolean, and vectorized integer (fancy) indexing are all accessible from `__{get,set}item__`. Users still have access to all the indexing methods if they want to be sure to use only basic indexing (integer + slices).
* Fall back on .vindex when basic indexing fails Addresses #657 This matches NumPy behaviour in that basic, boolean, and vectorized integer (fancy) indexing are all accessible from `__{get,set}item__`. Users still have access to all the indexing methods if they want to be sure to use only basic indexing (integer + slices). * Fix basic selection test now with no IndexError * Fix basic_selection_2d test with no vindex error * Add specific test for fancy indexing fallback * Update get/setitem docstrings * Update tutorial.rst * PEP8 fix * Rename test array to z as in other tests * Add release note * Avoid mixing slicing and array indexing in setitem * Actually test for fancy index rather than try/except * Add check for 1D fancy index (no tuple) * Add tests for implicit fancy indexing, and getitem * Add expected blank line * Add strict test for make_slice_selection * Ensure make_slice_selection returns valid NumPy slices * Make pytest verbose to see what is failing in windows * Add 5 min per-test timeout * Use private self._shape when determining ndim self.shape is a property that hides a lot of computation, and, more importantly, it can be waiting for an update and so .ndim *cannot* be accessed during a reshape/append. See: #725 (comment) This should prevent that behavior. Co-authored-by: Josh Moore <[email protected]>
Closed by #725! 🎉 |
Overview
Attempting to modify/retrive values in a zarr array with fancy indexing results in an error.
Minimal, reproducible code sample
For instance, a tuple of list indices
Results in the following:
However, this works using
vindex
Problem description
Zarr's
Array
class does not support fancy indexing via the standard numpy-like syntax, which causes issues when attempting to write to zarr arrays via napari's label layer. These problems arise because several of the label editing tools in napari (e.g., paintbrush, fill tool, etc) require fancy indexing. @jni and myself are hoping that the logic in vindex can be incorporated to Array's__setitem__
and__getitem__
. Any advice you can offer in this regard would be much appreciated!Version and installation information
zarr.__version__
--> 2.4.0numcodecs.__version__
--> 0.7.2The text was updated successfully, but these errors were encountered: