question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request for fancy indexing

See original GitHub issue

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

import zarr
array  = zarr.zeros((20, 20))
array[[1, 2, 3], [1, 2, 3]] = 1

Results in the following:

IndexError: unsupported selection item for basic indexing; expected integer or slice, got <class 'list'>

However, this works usingvindex

array.vindex[[1, 2, 3], [1, 2, 3]] = 1
print(array.vindex[[1, 2, 3], [1, 2, 3]])
# Output: [1. 1. 1.]

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.0
  • numcodecs.__version__ --> 0.7.2
  • Version of Python interpreter --> 3.8.5
  • Operating system --> Mac
  • How Zarr was installed --> conda

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jnicommented, Oct 20, 2021

Closed by #725! 🎉

1reaction
shoyercommented, Mar 3, 2021

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: https://github.com/dask/dask/issues/7313. Thus I would advise caution before relying on this feature 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fancy Indexing | Python Data Science Handbook
Fancy indexing is conceptually simple: it means passing an array of indices to ... The at() method does an in-place application of the...
Read more >
Fancy Indexing - Stanford University
Directory indexing will list the contents of the directory when the request is made. How to use fancy indexing. Actually, you don't have...
Read more >
Fancy indexing with assignment for numpy array
Normally, when you use arrays to index another array this way, numpy expects each array R , C , and so on, to...
Read more >
fancy indexing via a mix of NumPy array and list not working ...
The fancy indexing using a mix of NumPy boolean array and an explicit list does not seem to work in the latest h5py...
Read more >
What is fancy indexing in NumPy? - Educative.io
Fancy indexing is a method used when working in arrays. It is an advanced form of simple indexing. An index is used to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found