Skip to content

"Fancy" indexing a GPU-enabled zarr.Array #3640

@ilan-gold

Description

@ilan-gold

Zarr version

3.1.5

Numcodecs version

0.16.5

Python Version

3.12

Operating System

Linux

Installation

uv pip install

Description

The below example errors out with

Traceback (most recent call last):
  File "/home/ubuntu/anndata/tester.py", line 17, in <module>
    z["foo"][np.array([0, 2])]
    ~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/anndata/venv/lib/python3.12/site-packages/zarr/core/array.py", line 2866, in __getitem__
    return self.vindex[cast("CoordinateSelection | MaskSelection", selection)]
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/anndata/venv/lib/python3.12/site-packages/zarr/core/indexing.py", line 1321, in __getitem__
    return self.array.get_coordinate_selection(new_selection, fields=fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/anndata/venv/lib/python3.12/site-packages/zarr/core/array.py", line 3732, in get_coordinate_selection
    out_array = np.array(out_array).reshape(indexer.sel_shape)
                ^^^^^^^^^^^^^^^^^^^
  File "cupy/_core/core.pyx", line 1581, in cupy._core.core._ndarray_base.__array__
TypeError: Implicit conversion to a NumPy array is not allowed. Please use `.get()` to construct a NumPy array explicitly.

Steps to reproduce

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "zarr[gpu]@git+https://github.com/zarr-developers/zarr-python.git@main",
# ]
# ///
#
# This script automatically imports the development branch of zarr to check for issues

import zarr
import numpy as np


z = zarr.open("big_test.zarr", mode="w")
z.create_array("foo", data=np.arange(10), compressors=None)
with zarr.config.enable_gpu():
    z["foo"][np.array([0, 2])]

Additional output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions