|
3 | 3 |
|
4 | 4 | import numpy as np |
5 | 5 |
|
6 | | -from xarray.core import utils |
7 | 6 | from xarray.core.duck_array_ops import dask_available |
| 7 | +from xarray.core.indexing import ImplicitToExplicitIndexingAdapter |
8 | 8 | from xarray.core.parallelcompat import ChunkManagerEntrypoint, T_ChunkedArray, T_Chunks |
9 | 9 | from xarray.core.pycompat import is_duck_dask_array |
10 | 10 |
|
@@ -32,48 +32,15 @@ def chunks(self, data: "DaskArray") -> T_Chunks: |
32 | 32 | def from_array(self, data, chunks, **kwargs) -> "DaskArray": |
33 | 33 | import dask.array as da |
34 | 34 |
|
35 | | - from xarray.core import indexing |
36 | | - |
37 | | - # dask-specific kwargs |
38 | | - name = kwargs.pop("name", None) |
39 | | - lock = kwargs.pop("lock", False) |
40 | | - inline_array = kwargs.pop("inline_array", False) |
41 | | - |
42 | | - if is_duck_dask_array(data): |
43 | | - data = self.rechunk(data, chunks) |
44 | | - else: |
45 | | - # TODO move this up to variable.chunk |
46 | | - if isinstance(data, indexing.ExplicitlyIndexed): |
47 | | - # Unambiguously handle array storage backends (like NetCDF4 and h5py) |
48 | | - # that can't handle general array indexing. For example, in netCDF4 you |
49 | | - # can do "outer" indexing along two dimensions independent, which works |
50 | | - # differently from how NumPy handles it. |
51 | | - # da.from_array works by using lazy indexing with a tuple of slices. |
52 | | - # Using OuterIndexer is a pragmatic choice: dask does not yet handle |
53 | | - # different indexing types in an explicit way: |
54 | | - # https://github.com/dask/dask/issues/2883 |
55 | | - data = indexing.ImplicitToExplicitIndexingAdapter( |
56 | | - data, indexing.OuterIndexer |
57 | | - ) |
58 | | - |
59 | | - # All of our lazily loaded backend array classes should use NumPy |
60 | | - # array operations. |
61 | | - dask_kwargs = {"meta": np.ndarray} |
62 | | - else: |
63 | | - dask_kwargs = {} |
64 | | - |
65 | | - if utils.is_dict_like(chunks): |
66 | | - chunks = tuple(chunks.get(n, s) for n, s in enumerate(data.shape)) |
67 | | - |
68 | | - data = da.from_array( |
69 | | - data, |
70 | | - chunks, |
71 | | - name=name, |
72 | | - lock=lock, |
73 | | - inline_array=inline_array, |
74 | | - **dask_kwargs, |
75 | | - ) |
76 | | - return data |
| 35 | + if isinstance(data, ImplicitToExplicitIndexingAdapter): |
| 36 | + # lazily loaded backend array classes should use NumPy array operations. |
| 37 | + kwargs["meta"] = np.ndarray |
| 38 | + |
| 39 | + return da.from_array( |
| 40 | + data, |
| 41 | + chunks, |
| 42 | + **kwargs, |
| 43 | + ) |
77 | 44 |
|
78 | 45 | def compute(self, *data: "DaskArray", **kwargs) -> np.ndarray: |
79 | 46 | from dask.array import compute |
|
0 commit comments