Why am I getting this error when I try to slice a Zarr array exactly the same way I would slice a Numpy array?

470 Views Asked by At

I am using the following code to slice a Zarr array from disk:

import zarr as zr

db = zr.open('/content/drive/My Drive/Share/Daily Data/Database/dbz.zarr', mode='r')
data = db[db[:,0]==20171003]

Here is the error:

IndexError                                Traceback (most recent call last)
<ipython-input-16-4ae364a8c3b1> in <module>()
      1 dbz_ranked = zr.open('/content/drive/My Drive/Share/Daily Data/Database/dbz_ranked.zarr', mode='w', shape=(8245164, 345),chunks=(100000, 345), dtype='float64')
----> 2   data = db[db[:,0]==20171003]


3 frames
/usr/local/lib/python3.6/dist-packages/zarr/indexing.py in __init__(self, selection, array)
    280                 raise IndexError('unsupported selection item for basic indexing; '
    281                                  'expected integer or slice, got {!r}'
--> 282                                  .format(type(dim_sel)))
    283 
    284             dim_indexers.append(dim_indexer)

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

I have no clue why this isn't working, I thought Zarr was supposed to slice just like a Numpy array?

1

There are 1 best solutions below

1
On

I found the following page to be helpful: https://zarr.readthedocs.io/en/stable/api/core.html

In summary, using zarr_array.oindex([]) allows classic indexing/slicing.