diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 1eca1d30e72..75416756aa9 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -102,6 +102,9 @@ Internal Changes - Adds :py:func:`open_datatree` into ``xarray/backends`` (:pull:`8697`) By `Matt Savoie `_. +- Refactor :py:meth:`xarray.core.indexing.DaskIndexingAdapter.__getitem__` to remove an unnecessary rewrite of the indexer key + (:issue: `8377`, :pull:`8758`) By `Anderson Banihirwe ` + .. _whats-new.2024.01.1: v2024.01.1 (23 Jan, 2024) diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index 061f41c22b2..7331ab1a056 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -4,7 +4,7 @@ import functools import operator from collections import Counter, defaultdict -from collections.abc import Hashable, Iterable, Mapping +from collections.abc import Hashable, Mapping from contextlib import suppress from dataclasses import dataclass, field from datetime import timedelta @@ -1418,23 +1418,6 @@ def __init__(self, array): self.array = array def __getitem__(self, key): - if not isinstance(key, VectorizedIndexer): - # if possible, short-circuit when keys are effectively slice(None) - # This preserves dask name and passes lazy array equivalence checks - # (see duck_array_ops.lazy_array_equiv) - rewritten_indexer = False - new_indexer = [] - for idim, k in enumerate(key.tuple): - if isinstance(k, Iterable) and ( - not is_duck_dask_array(k) - and duck_array_ops.array_equiv(k, np.arange(self.array.shape[idim])) - ): - new_indexer.append(slice(None)) - rewritten_indexer = True - else: - new_indexer.append(k) - if rewritten_indexer: - key = type(key)(tuple(new_indexer)) if isinstance(key, BasicIndexer): return self.array[key.tuple] diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py index b2d18012fb0..07bf773cc88 100644 --- a/xarray/tests/test_dask.py +++ b/xarray/tests/test_dask.py @@ -1662,16 +1662,10 @@ def test_lazy_array_equiv_merge(compat): lambda a: a.assign_attrs(new_attr="anew"), lambda a: a.assign_coords(cxy=a.cxy), lambda a: a.copy(), - lambda a: a.isel(x=np.arange(a.sizes["x"])), lambda a: a.isel(x=slice(None)), lambda a: a.loc[dict(x=slice(None))], - lambda a: a.loc[dict(x=np.arange(a.sizes["x"]))], - lambda a: a.loc[dict(x=a.x)], - lambda a: a.sel(x=a.x), - lambda a: a.sel(x=a.x.values), lambda a: a.transpose(...), lambda a: a.squeeze(), # no dimensions to squeeze - lambda a: a.sortby("x"), # "x" is already sorted lambda a: a.reindex(x=a.x), lambda a: a.reindex_like(a), lambda a: a.rename({"cxy": "cnew"}).rename({"cnew": "cxy"}),