@@ -974,7 +974,7 @@ def test_indexing_1d_object_array() -> None:
974974
975975
976976@requires_dask
977- def test_indexing_dask_array ():
977+ def test_indexing_dask_array () -> None :
978978 import dask .array
979979
980980 da = DataArray (
@@ -988,7 +988,7 @@ def test_indexing_dask_array():
988988
989989
990990@requires_dask
991- def test_indexing_dask_array_scalar ():
991+ def test_indexing_dask_array_scalar () -> None :
992992 # GH4276
993993 import dask .array
994994
@@ -1002,19 +1002,37 @@ def test_indexing_dask_array_scalar():
10021002
10031003
10041004@requires_dask
1005- def test_vectorized_indexing_dask_array ():
1005+ def test_vectorized_indexing_dask_array () -> None :
10061006 # https://github.com/pydata/xarray/issues/2511#issuecomment-563330352
10071007 darr = DataArray (data = [0.2 , 0.4 , 0.6 ], coords = {"z" : range (3 )}, dims = ("z" ,))
10081008 indexer = DataArray (
10091009 data = np .random .randint (0 , 3 , 8 ).reshape (4 , 2 ).astype (int ),
10101010 coords = {"y" : range (4 ), "x" : range (2 )},
10111011 dims = ("y" , "x" ),
10121012 )
1013- darr [indexer .chunk ({"y" : 2 })]
1013+ expected = darr [indexer ]
1014+
1015+ # fails because we can't index pd.Index lazily (yet)
1016+ with pytest .raises (ValueError , match = "Cannot index with" ):
1017+ with raise_if_dask_computes ():
1018+ darr .chunk ()[indexer .chunk ({"y" : 2 })]
1019+
1020+ # fails because we can't index pd.Index lazily (yet)
1021+ with pytest .raises (ValueError , match = "Cannot index with" ):
1022+ with raise_if_dask_computes ():
1023+ actual = darr [indexer .chunk ({"y" : 2 })]
1024+
1025+ with raise_if_dask_computes ():
1026+ actual = darr .drop_vars ("z" ).chunk ()[indexer .chunk ({"y" : 2 })]
1027+ assert_identical (actual , expected .drop_vars ("z" ))
1028+
1029+ with raise_if_dask_computes ():
1030+ actual = darr .variable .chunk ()[indexer .variable .chunk ({"y" : 2 })]
1031+ assert_identical (actual , expected .variable )
10141032
10151033
10161034@requires_dask
1017- def test_advanced_indexing_dask_array ():
1035+ def test_advanced_indexing_dask_array () -> None :
10181036 # GH4663
10191037 import dask .array as da
10201038
0 commit comments