File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1082,3 +1082,32 @@ def test_update_attributes_group(store: Store):
1082
1082
1083
1083
g = Group .open (store / "update_attributes_group" )
1084
1084
assert g .metadata .attributes ["hello" ] == "zarrita"
1085
+
1086
+
1087
+ @pytest .mark .parametrize (
1088
+ "index_location" , [ShardingCodecIndexLocation .start , ShardingCodecIndexLocation .end ]
1089
+ )
1090
+ def test_sharding_with_empty_inner_chunk (store : Store , index_location ):
1091
+ data = np .arange (0 , 16 * 16 , dtype = "uint16" ).reshape ((16 , 16 ))
1092
+ fill_value = 1
1093
+ data [:4 , :4 ] = fill_value
1094
+
1095
+ a = Array .create (
1096
+ store / "sharding_with_empty_inner_chunk" ,
1097
+ shape = (16 , 16 ),
1098
+ chunk_shape = (8 , 8 ),
1099
+ dtype = data .dtype ,
1100
+ fill_value = fill_value ,
1101
+ codecs = [
1102
+ codecs .sharding_codec (
1103
+ chunk_shape = (4 , 4 ),
1104
+ codecs = [
1105
+ codecs .bytes_codec (),
1106
+ codecs .blosc_codec (typesize = data .dtype .itemsize ),
1107
+ ],
1108
+ index_location = index_location ,
1109
+ )
1110
+ ],
1111
+ )
1112
+ a [:] = data
1113
+ assert np .array_equal (a [:], data )
Original file line number Diff line number Diff line change @@ -191,7 +191,8 @@ async def finalize(
191
191
) -> BytesLike :
192
192
index_bytes = await index_encoder (self .index )
193
193
if index_location == ShardingCodecIndexLocation .start :
194
- self .index .offsets_and_lengths [..., 0 ] += len (index_bytes )
194
+ empty_chunks_mask = self .index .offsets_and_lengths [..., 0 ] == MAX_UINT_64
195
+ self .index .offsets_and_lengths [~ empty_chunks_mask , 0 ] += len (index_bytes )
195
196
index_bytes = await index_encoder (
196
197
self .index
197
198
) # encode again with corrected offsets
You can’t perform that action at this time.
0 commit comments