File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 19
19
is_duck_dask_array ,
20
20
sparse_array_type ,
21
21
)
22
- from .utils import maybe_cast_to_coords_dtype
22
+ from .utils import maybe_cast_to_coords_dtype , is_duck_array
23
23
24
24
25
25
def expanded_indexer (key , ndim ):
@@ -308,7 +308,7 @@ def __init__(self, key):
308
308
for k in key :
309
309
if isinstance (k , slice ):
310
310
k = as_integer_slice (k )
311
- elif isinstance ( k , np . ndarray ) or isinstance ( k , da . Array ):
311
+ elif is_duck_array ( k ):
312
312
if not np .issubdtype (k .dtype , np .integer ):
313
313
raise TypeError (
314
314
f"invalid indexer array, does not have integer dtype: { k !r} "
@@ -321,10 +321,7 @@ def __init__(self, key):
321
321
"invalid indexer key: ndarray arguments "
322
322
f"have different numbers of dimensions: { ndims } "
323
323
)
324
- if isinstance (k , da .Array ):
325
- k = da .asarray (k , dtype = np .int64 )
326
- else :
327
- k = np .asarray (k , dtype = np .int64 )
324
+ k = k .astype (np .int64 )
328
325
else :
329
326
raise TypeError (
330
327
f"unexpected indexer type for { type (self ).__name__ } : { k !r} "
Original file line number Diff line number Diff line change 9
9
10
10
from . import IndexerMaker , ReturnItem , assert_array_equal
11
11
12
+ da = pytest .importorskip ("dask.array" )
13
+
12
14
B = IndexerMaker (indexing .BasicIndexer )
13
15
14
16
@@ -729,3 +731,16 @@ def test_indexing_1d_object_array() -> None:
729
731
expected = DataArray (expected_data )
730
732
731
733
assert [actual .data .item ()] == [expected .data .item ()]
734
+
735
+
736
+ def test_indexing_dask_array ():
737
+ da = DataArray (
738
+ np .ones (10 * 3 * 3 ).reshape ((10 , 3 , 3 )),
739
+ dims = ('time' , 'x' , 'y' ),
740
+ ).chunk (dict (time = - 1 , x = 1 , y = 1 ))
741
+ da [{"time" : 9 }]= 42
742
+
743
+ idx = da .argmax ('time' )
744
+ actual = da .isel (time = idx )
745
+
746
+ assert np .all (actual == 42 )
You can’t perform that action at this time.
0 commit comments