From 7c660d73e8a65fd49d0672ea12d5fa0f0ab42cf2 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Wed, 26 Feb 2025 15:23:36 -0700 Subject: [PATCH 1/6] [WIP] cupy zarr fixes --- xarray/core/indexes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xarray/core/indexes.py b/xarray/core/indexes.py index 43e231e84d4..a65e1ff3673 100644 --- a/xarray/core/indexes.py +++ b/xarray/core/indexes.py @@ -442,6 +442,7 @@ def safe_cast_to_index(array: Any) -> pd.Index: """ from xarray.core.dataarray import DataArray from xarray.core.variable import Variable + from xarray.namedarray.pycompat import to_numpy if isinstance(array, pd.Index): index = array @@ -468,7 +469,7 @@ def safe_cast_to_index(array: Any) -> pd.Index: ) kwargs["dtype"] = "float64" - index = pd.Index(np.asarray(array), **kwargs) + index = pd.Index(to_numpy(array), **kwargs) return _maybe_cast_to_cftimeindex(index) From 7a4d4e5fe8ab831f83a0c5d416a192dbe9a78a7b Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Wed, 26 Feb 2025 15:36:18 -0700 Subject: [PATCH 2/6] one more --- xarray/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index 521abcdfddd..b2c9530c164 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -1014,7 +1014,7 @@ def explicit_indexing_adapter( result = raw_indexing_method(raw_key.tuple) if numpy_indices.tuple: # index the loaded np.ndarray - indexable = NumpyIndexingAdapter(result) + indexable = as_indexable(result) result = apply_indexer(indexable, numpy_indices) return result From a1debcd836ee4e03def5cbc960586fb49fda6901 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Wed, 26 Feb 2025 15:59:33 -0700 Subject: [PATCH 3/6] Add test --- xarray/tests/test_indexing.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xarray/tests/test_indexing.py b/xarray/tests/test_indexing.py index d9784e6a62e..6b2842107a6 100644 --- a/xarray/tests/test_indexing.py +++ b/xarray/tests/test_indexing.py @@ -19,6 +19,7 @@ raise_if_dask_computes, requires_dask, ) +from xarray.tests.arrays import DuckArrayWrapper B = IndexerMaker(indexing.BasicIndexer) @@ -1052,3 +1053,14 @@ def test_advanced_indexing_dask_array() -> None: with raise_if_dask_computes(): actual = ds.b.sel(x=ds.a.data) assert_identical(expected, actual) + + +def test_backend_indexing_non_numpy() -> None: + array = DuckArrayWrapper(np.array([1, 2, 3])) + indexed = indexing.explicit_indexing_adapter( + indexing.BasicIndexer((slice(1),)), + shape=array.shape, + indexing_support=indexing.IndexingSupport.BASIC, + raw_indexing_method=array.__getitem__, + ) + np.testing.assert_array_equal(indexed.array, np.array([1])) From d00805d87f4c0c89b64b7bdd99ec39c71b8bcca2 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Wed, 26 Feb 2025 16:02:58 -0700 Subject: [PATCH 4/6] update comment --- xarray/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index b2c9530c164..70d6974f5ec 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -1013,7 +1013,7 @@ def explicit_indexing_adapter( raw_key, numpy_indices = decompose_indexer(key, shape, indexing_support) result = raw_indexing_method(raw_key.tuple) if numpy_indices.tuple: - # index the loaded np.ndarray + # index the loaded duck array indexable = as_indexable(result) result = apply_indexer(indexable, numpy_indices) return result From 0c7e7a0c4293c78744445b05329e423241b5b80b Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Wed, 26 Feb 2025 16:04:41 -0700 Subject: [PATCH 5/6] add whats-new --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index d9d4998d983..94e3d77184a 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -30,6 +30,8 @@ New Features By `Justus Magin `_. - Added experimental support for coordinate transforms (not ready for public use yet!) (:pull:`9543`) By `Benoit Bovy `_. +- Support reading to `GPU memory with Zarr `_ (:pull:`10078`). + By `Deepak Cherian `_. Breaking changes ~~~~~~~~~~~~~~~~ From f8ba4c161de4d249646ab6575e10fdd0db05de16 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Wed, 26 Feb 2025 16:06:54 -0700 Subject: [PATCH 6/6] add comment --- xarray/tests/test_indexing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/tests/test_indexing.py b/xarray/tests/test_indexing.py index 6b2842107a6..c39062b8419 100644 --- a/xarray/tests/test_indexing.py +++ b/xarray/tests/test_indexing.py @@ -1056,6 +1056,7 @@ def test_advanced_indexing_dask_array() -> None: def test_backend_indexing_non_numpy() -> None: + """This model indexing of a Zarr store that reads to GPU memory.""" array = DuckArrayWrapper(np.array([1, 2, 3])) indexed = indexing.explicit_indexing_adapter( indexing.BasicIndexer((slice(1),)), pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy