@@ -490,7 +490,8 @@ def test_invalid_shard_shape() -> None:
490490 with pytest .raises (
491491 ValueError ,
492492 match = re .escape (
493- "The array's `chunk_shape` (got (16, 16)) needs to be divisible by the shard's inner `chunk_shape` (got (9,))."
493+ "The array's `chunk_shape` (got (16, 16)) needs to be divisible "
494+ "by the shard's inner `chunk_shape` (got (9,))."
494495 ),
495496 ):
496497 zarr .create_array (
@@ -501,3 +502,56 @@ def test_invalid_shard_shape() -> None:
501502 dtype = np .dtype ("uint8" ),
502503 fill_value = 0 ,
503504 )
505+
506+
507+ @pytest .mark .parametrize ("store" , ["local" ], indirect = ["store" ])
508+ def test_sharding_mixed_integer_list_indexing (store : Store ) -> None :
509+ """Regression test for https://github.com/zarr-developers/zarr-python/issues/3691.
510+
511+ Mixed integer/list indexing on sharded arrays should return the same
512+ shape and data as on equivalent chunked arrays.
513+ """
514+ import numpy as np
515+
516+ data = np .arange (200 * 100 * 10 , dtype = np .uint8 ).reshape (200 , 100 , 10 )
517+
518+ chunked = zarr .create_array (
519+ store ,
520+ name = "chunked" ,
521+ shape = (200 , 100 , 10 ),
522+ dtype = np .uint8 ,
523+ chunks = (200 , 100 , 1 ),
524+ overwrite = True ,
525+ )
526+ chunked [:, :, :] = data
527+
528+ sharded = zarr .create_array (
529+ store ,
530+ name = "sharded" ,
531+ shape = (200 , 100 , 10 ),
532+ dtype = np .uint8 ,
533+ chunks = (200 , 100 , 1 ),
534+ shards = (200 , 100 , 10 ),
535+ overwrite = True ,
536+ )
537+ sharded [:, :, :] = data
538+
539+ # Mixed integer + list indexing
540+ c = chunked [0 :10 , 0 , [0 , 1 ]] # type: ignore[index]
541+ s = sharded [0 :10 , 0 , [0 , 1 ]] # type: ignore[index]
542+ assert c .shape == s .shape == (10 , 2 ), ( # type: ignore[union-attr]
543+ f"Expected (10, 2), got chunked={ c .shape } , sharded={ s .shape } " # type: ignore[union-attr]
544+ )
545+ np .testing .assert_array_equal (c , s )
546+
547+ # Multiple integer axes
548+ c2 = chunked [0 , 0 , [0 , 1 , 2 ]] # type: ignore[index]
549+ s2 = sharded [0 , 0 , [0 , 1 , 2 ]] # type: ignore[index]
550+ assert c2 .shape == s2 .shape == (3 ,) # type: ignore[union-attr]
551+ np .testing .assert_array_equal (c2 , s2 )
552+
553+ # Slice + integer + slice
554+ c3 = chunked [0 :5 , 1 , 0 :3 ]
555+ s3 = sharded [0 :5 , 1 , 0 :3 ]
556+ assert c3 .shape == s3 .shape == (5 , 3 ) # type: ignore[union-attr]
557+ np .testing .assert_array_equal (c3 , s3 )
0 commit comments