Skip to content

Commit 71d5ff6

Browse files
committed
Attempt to fix indexing for Dask
This is a naive attempt to make `isel` work with Dask Known limitation: it triggers the computation.
1 parent 07de257 commit 71d5ff6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

xarray/core/indexing.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from contextlib import suppress
66
from datetime import timedelta
77
from typing import Any, Callable, Iterable, List, Optional, Tuple, Union
8+
import dask.array as da
89

910
import numpy as np
1011
import pandas as pd
@@ -307,7 +308,7 @@ def __init__(self, key):
307308
for k in key:
308309
if isinstance(k, slice):
309310
k = as_integer_slice(k)
310-
elif isinstance(k, np.ndarray):
311+
elif isinstance(k, np.ndarray) or isinstance(k, da.Array):
311312
if not np.issubdtype(k.dtype, np.integer):
312313
raise TypeError(
313314
f"invalid indexer array, does not have integer dtype: {k!r}"
@@ -320,7 +321,10 @@ def __init__(self, key):
320321
"invalid indexer key: ndarray arguments "
321322
f"have different numbers of dimensions: {ndims}"
322323
)
323-
k = np.asarray(k, dtype=np.int64)
324+
if isinstance(k, da.Array):
325+
k = da.asarray(k, dtype=np.int64)
326+
else:
327+
k = np.asarray(k, dtype=np.int64)
324328
else:
325329
raise TypeError(
326330
f"unexpected indexer type for {type(self).__name__}: {k!r}"
@@ -973,7 +977,6 @@ def _arrayize_vectorized_indexer(indexer, shape):
973977

974978
def _dask_array_with_chunks_hint(array, chunks):
975979
"""Create a dask array using the chunks hint for dimensions of size > 1."""
976-
import dask.array as da
977980

978981
if len(chunks) < array.ndim:
979982
raise ValueError("not enough chunks in hint")

0 commit comments

Comments
 (0)