@@ -195,8 +195,13 @@ def test_create_array_defaults(store: Store):
195
195
)
196
196
197
197
198
- @pytest .mark .parametrize ("order" , ["C" , "F" ])
199
- def test_v2_non_contiguous (order : Literal ["C" , "F" ]) -> None :
198
+ @pytest .mark .parametrize ("numpy_order" , ["C" , "F" ])
199
+ @pytest .mark .parametrize ("zarr_order" , ["C" , "F" ])
200
+ def test_v2_non_contiguous (numpy_order : Literal ["C" , "F" ], zarr_order : Literal ["C" , "F" ]) -> None :
201
+ """
202
+ Make sure zarr v2 arrays save data using the memory order given to the zarr array,
203
+ not the memory order of the original numpy array.
204
+ """
200
205
store = MemoryStore ()
201
206
arr = zarr .create_array (
202
207
store ,
@@ -208,25 +213,27 @@ def test_v2_non_contiguous(order: Literal["C", "F"]) -> None:
208
213
filters = None ,
209
214
compressors = None ,
210
215
overwrite = True ,
211
- order = order ,
216
+ order = zarr_order ,
212
217
)
213
218
214
- # Non-contiguous write
215
- a = np .arange (arr .shape [0 ] * arr .shape [1 ]).reshape (arr .shape , order = order )
219
+ # Non-contiguous write, using numpy memory order
220
+ a = np .arange (arr .shape [0 ] * arr .shape [1 ]).reshape (arr .shape , order = numpy_order )
216
221
arr [6 :9 , 3 :6 ] = a [6 :9 , 3 :6 ] # The slice on the RHS is important
217
222
np .testing .assert_array_equal (arr [6 :9 , 3 :6 ], a [6 :9 , 3 :6 ])
218
223
219
224
np .testing .assert_array_equal (
220
225
a [6 :9 , 3 :6 ],
221
226
np .frombuffer (
222
227
sync (store .get ("2.1" , default_buffer_prototype ())).to_bytes (), dtype = "float64"
223
- ).reshape ((3 , 3 ), order = order ),
228
+ ).reshape ((3 , 3 ), order = zarr_order ),
224
229
)
225
- if order == "F" :
230
+ # After writing and reading from zarr array, order should be same as zarr order
231
+ if zarr_order == "F" :
226
232
assert (arr [6 :9 , 3 :6 ]).flags .f_contiguous
227
233
else :
228
234
assert (arr [6 :9 , 3 :6 ]).flags .c_contiguous
229
235
236
+ # Contiguous write
230
237
store = MemoryStore ()
231
238
arr = zarr .create_array (
232
239
store ,
@@ -238,17 +245,17 @@ def test_v2_non_contiguous(order: Literal["C", "F"]) -> None:
238
245
compressors = None ,
239
246
filters = None ,
240
247
overwrite = True ,
241
- order = order ,
248
+ order = zarr_order ,
242
249
)
243
250
244
- # Contiguous write
245
- a = np .arange (9 ).reshape ((3 , 3 ), order = order )
246
- if order == "F" :
247
- assert a .flags .f_contiguous
248
- else :
249
- assert a .flags .c_contiguous
251
+ a = np .arange (9 ).reshape ((3 , 3 ), order = numpy_order )
250
252
arr [6 :9 , 3 :6 ] = a
251
253
np .testing .assert_array_equal (arr [6 :9 , 3 :6 ], a )
254
+ # After writing and reading from zarr array, order should be same as zarr order
255
+ if zarr_order == "F" :
256
+ assert (arr [6 :9 , 3 :6 ]).flags .f_contiguous
257
+ else :
258
+ assert (arr [6 :9 , 3 :6 ]).flags .c_contiguous
252
259
253
260
254
261
def test_default_compressor_deprecation_warning ():
0 commit comments