Skip to content
forked from pydata/xarray

Commit

Permalink
Revert "[WIP] ExplicitlyIndexedBackendArray"
Browse files Browse the repository at this point in the history
This reverts commit 9b727e6.
  • Loading branch information
dcherian committed Jan 18, 2023
1 parent b19a24b commit 84f560f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 32 deletions.
5 changes: 2 additions & 3 deletions xarray/backends/cfgrib_.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
AbstractDataStore,
BackendArray,
BackendEntrypoint,
ExplicitlyIndexedBackendArray,
_normalize_path,
)
from .locks import SerializableLock, ensure_lock
Expand All @@ -33,8 +32,8 @@ def __init__(self, datastore, array):
self.array = array

def __getitem__(self, key):
return ExplicitlyIndexedBackendArray(
self, key, self.shape, indexing.IndexingSupport.BASIC, self._getitem
return indexing.explicit_indexing_adapter(
key, self.shape, indexing.IndexingSupport.BASIC, self._getitem
)

def _getitem(self, key):
Expand Down
19 changes: 0 additions & 19 deletions xarray/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,6 @@ def get_duck_array(self, dtype=None):
return self[key]


class ExplicitlyIndexedBackendArray(BackendArray):
def __init__(
self, backend_array, key, shape, indexing_support, raw_indexing_method
):
self.backend_array = backend_array
self.key = key
self.shape = shape
self.indexing_support = indexing_support
self.raw_indexing_method = raw_indexing_method

def get_duck_array(self):
return indexing.explicit_indexing_adapter(
self.key, self.shape, self.indexing_support, self.raw_indexing_method
)

def repr(self):
return f"ExplicitlyIndexedBackendArray({type(self.backend_array)})"


class AbstractDataStore:
__slots__ = ()

Expand Down
5 changes: 2 additions & 3 deletions xarray/backends/h5netcdf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .common import (
BACKEND_ENTRYPOINTS,
BackendEntrypoint,
ExplicitlyIndexedBackendArray,
WritableCFDataStore,
_normalize_path,
find_root_and_group,
Expand All @@ -42,8 +41,8 @@ def get_array(self, needs_lock=True):
return ds.variables[self.variable_name]

def __getitem__(self, key):
return ExplicitlyIndexedBackendArray(
self, key, self.shape, indexing.IndexingSupport.OUTER_1VECTOR, self._getitem
return indexing.explicit_indexing_adapter(
key, self.shape, indexing.IndexingSupport.OUTER_1VECTOR, self._getitem
)

def _getitem(self, key):
Expand Down
5 changes: 2 additions & 3 deletions xarray/backends/netCDF4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
BACKEND_ENTRYPOINTS,
BackendArray,
BackendEntrypoint,
ExplicitlyIndexedBackendArray,
WritableCFDataStore,
_normalize_path,
find_root_and_group,
Expand Down Expand Up @@ -83,8 +82,8 @@ def get_array(self, needs_lock=True):
return variable

def __getitem__(self, key):
return ExplicitlyIndexedBackendArray(
self, key, self.shape, indexing.IndexingSupport.OUTER, self._getitem
return indexing.explicit_indexing_adapter(
key, self.shape, indexing.IndexingSupport.OUTER, self._getitem
)

def _getitem(self, key):
Expand Down
4 changes: 1 addition & 3 deletions xarray/coding/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,4 @@ def __getitem__(self, key):
key = type(key)(indexing.expanded_indexer(key.tuple, self.array.ndim))
if key.tuple[-1] != slice(None):
raise IndexError("too many indices")

dtype = "S" + str(self.array.shape[-1])
return lazy_elemwise_func(self.array[key], _numpy_char_to_bytes, dtype)
return _numpy_char_to_bytes(self.array[key])
7 changes: 6 additions & 1 deletion xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,12 @@ def shape(self) -> tuple[int, ...]:
def get_duck_array(self):
array = as_indexable(self.array)
array = array[self.key]
array = array.get_duck_array()
# array[self.key] is now a numpy array when
# self.array is a BackendArray subclass
# and self.key is BasicIndexer((slice(None, None, None),))
# so we need the explicit check for ExplicitlyIndexed
if isinstance(array, ExplicitlyIndexed):
array = array.get_duck_array()
return array

def transpose(self, order):
Expand Down

0 comments on commit 84f560f

Please sign in to comment.