Skip to content

Commit f194cdf

Browse files
authored
Merge pull request #2 from TomNicholas/remove_indexing_adapter
Remove explicit indexing adapter
2 parents 76e790c + 112bb18 commit f194cdf

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

cubed_xarray/cubedmanager.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,19 @@ def chunks(self, data: "CubedArray") -> T_Chunks:
3535
return data.chunks
3636

3737
def from_array(self, data: np.ndarray, chunks, **kwargs) -> "CubedArray":
38-
from cubed import Array, from_array
38+
from cubed import from_array
3939

40-
from xarray.core import indexing
41-
42-
# cubed-specific kwargs
40+
# Extract cubed-specific kwargs.
41+
# Also ignores dask-specific kwargs that are passed in.
42+
# The passing of dask-specific kwargs to cubed should be eventually removed by deprecating them
43+
# as explicit arguments to xarray methods
4344
spec = kwargs.pop("spec", None)
4445

45-
if isinstance(data, Array):
46-
data = data.rechunk(chunks)
47-
elif is_duck_dask_array(data):
48-
raise TypeError("Trying to rechunk a dask array using cubed")
49-
else:
50-
if isinstance(data, indexing.ExplicitlyIndexed):
51-
# Unambiguously handle array storage backends (like NetCDF4 and h5py)
52-
# that can't handle general array indexing. For example, in netCDF4 you
53-
# can do "outer" indexing along two dimensions independent, which works
54-
# differently from how NumPy handles it.
55-
# da.from_array works by using lazy indexing with a tuple of slices.
56-
# Using OuterIndexer is a pragmatic choice: dask does not yet handle
57-
# different indexing types in an explicit way:
58-
# https://github.com/dask/dask/issues/2883
59-
data = indexing.ImplicitToExplicitIndexingAdapter(
60-
data, indexing.OuterIndexer
61-
)
62-
63-
if utils.is_dict_like(chunks):
64-
chunks = tuple(chunks.get(n, s) for n, s in enumerate(data.shape))
65-
66-
data = from_array(
67-
data,
68-
chunks,
69-
spec=spec,
70-
)
71-
72-
return data
46+
return from_array(
47+
data,
48+
chunks,
49+
spec=spec,
50+
)
7351

7452
def rechunk(self, data: "CubedArray", chunks, **kwargs) -> "CubedArray":
7553
return data.rechunk(chunks, **kwargs)

0 commit comments

Comments
 (0)