@@ -204,7 +204,6 @@ def test_get_basic_selection_0d(store: StorePath, use_out: bool, value: Any, dty
204204 slice (50 , 150 , 10 ),
205205]
206206
207-
208207basic_selections_1d_bad = [
209208 # only positive step supported
210209 slice (None , None , - 1 ),
@@ -305,7 +304,6 @@ def test_get_basic_selection_1d(store: StorePath):
305304 (Ellipsis , slice (None ), slice (None )),
306305]
307306
308-
309307basic_selections_2d_bad = [
310308 # bad stuff
311309 2.3 ,
@@ -1272,6 +1270,8 @@ def _test_get_mask_selection(a, z, selection):
12721270 assert_array_equal (expect , actual )
12731271 actual = z .vindex [selection ]
12741272 assert_array_equal (expect , actual )
1273+ actual = z [selection ]
1274+ assert_array_equal (expect , actual )
12751275
12761276
12771277mask_selections_1d_bad = [
@@ -1344,6 +1344,9 @@ def _test_set_mask_selection(v, a, z, selection):
13441344 z [:] = 0
13451345 z .vindex [selection ] = v [selection ]
13461346 assert_array_equal (a , z [:])
1347+ z [:] = 0
1348+ z [selection ] = v [selection ]
1349+ assert_array_equal (a , z [:])
13471350
13481351
13491352def test_set_mask_selection_1d (store : StorePath ):
@@ -1726,3 +1729,51 @@ def test_accessed_chunks(shape, chunks, ops):
17261729 ) == 1
17271730 # Check that no other chunks were accessed
17281731 assert len (delta_counts ) == 0
1732+
1733+
1734+ @pytest .mark .parametrize (
1735+ "selection" ,
1736+ [
1737+ # basic selection
1738+ [...],
1739+ [1 , ...],
1740+ [slice (None )],
1741+ [1 , 3 ],
1742+ [[1 , 2 , 3 ], 9 ],
1743+ [np .arange (1000 )],
1744+ [slice (5 , 15 )],
1745+ [slice (2 , 4 ), 4 ],
1746+ [[1 , 3 ]],
1747+ # mask selection
1748+ [np .tile ([True , False ], (1000 , 5 ))],
1749+ [np .full ((1000 , 10 ), False )],
1750+ # coordinate selection
1751+ [[1 , 2 , 3 , 4 ], [5 , 6 , 7 , 8 ]],
1752+ [[100 , 200 , 300 ], [4 , 5 , 6 ]],
1753+ ],
1754+ )
1755+ def test_indexing_equals_numpy (store , selection ):
1756+ a = np .arange (10000 , dtype = int ).reshape (1000 , 10 )
1757+ z = zarr_array_from_numpy_array (store , a , chunk_shape = (300 , 3 ))
1758+ # note: in python 3.10 a[*selection] is not valid unpacking syntax
1759+ expected = a [(* selection ,)]
1760+ actual = z [(* selection ,)]
1761+ assert_array_equal (expected , actual , err_msg = f"selection: { selection } " )
1762+
1763+
1764+ @pytest .mark .parametrize (
1765+ "selection" ,
1766+ [
1767+ [np .tile ([True , False ], 500 ), np .tile ([True , False ], 5 )],
1768+ [np .full (1000 , False ), np .tile ([True , False ], 5 )],
1769+ [np .full (1000 , True ), np .full (10 , True )],
1770+ [np .full (1000 , True ), [True , False ] * 5 ],
1771+ ],
1772+ )
1773+ def test_orthogonal_bool_indexing_like_numpy_ix (store , selection ):
1774+ a = np .arange (10000 , dtype = int ).reshape (1000 , 10 )
1775+ z = zarr_array_from_numpy_array (store , a , chunk_shape = (300 , 3 ))
1776+ expected = a [np .ix_ (* selection )]
1777+ # note: in python 3.10 z[*selection] is not valid unpacking syntax
1778+ actual = z [(* selection ,)]
1779+ assert_array_equal (expected , actual , err_msg = f"{ selection = } " )
0 commit comments