1212import  zarr .core .buffer 
1313import  zarr .storage 
1414from  zarr  import  config 
15+ from  zarr .core .buffer .core  import  default_buffer_prototype 
16+ from  zarr .core .sync  import  sync 
1517from  zarr .storage  import  MemoryStore , StorePath 
1618
1719
@@ -166,36 +168,54 @@ def test_v2_filters_codecs(filters: Any, order: Literal["C", "F"]) -> None:
166168
167169@pytest .mark .parametrize ("array_order" , ["C" , "F" ]) 
168170@pytest .mark .parametrize ("data_order" , ["C" , "F" ]) 
169- def  test_v2_non_contiguous (array_order : Literal ["C" , "F" ], data_order : Literal ["C" , "F" ]) ->  None :
171+ @pytest .mark .parametrize ("memory_order" , ["C" , "F" ]) 
172+ def  test_v2_non_contiguous (
173+     array_order : Literal ["C" , "F" ], data_order : Literal ["C" , "F" ], memory_order : Literal ["C" , "F" ]
174+ ) ->  None :
175+     store  =  MemoryStore ()
170176    arr  =  zarr .create_array (
171-         MemoryStore ({}) ,
177+         store ,
172178        shape = (10 , 8 ),
173179        chunks = (3 , 3 ),
174180        fill_value = np .nan ,
175181        dtype = "float64" ,
176182        zarr_format = 2 ,
183+         filters = None ,
184+         compressors = None ,
177185        overwrite = True ,
178186        order = array_order ,
187+         config = {"order" : memory_order },
179188    )
180189
181190    # Non-contiguous write 
182191    a  =  np .arange (arr .shape [0 ] *  arr .shape [1 ]).reshape (arr .shape , order = data_order )
183-     arr [slice ( 6 ,  9 , None ),  slice ( 3 ,  6 ,  None ) ] =  a [
184-          slice ( 6 ,  9 , None ),  slice ( 3 ,  6 ,  None )
185-     ]   # The slice on the RHS is important 
192+     arr [6 : 9 , 3 : 6 ] =  a [6 : 9 ,  3 : 6 ]   # The slice on the RHS is important 
193+     np . testing . assert_array_equal ( arr [ 6 : 9 , 3 : 6 ],  a [ 6 : 9 ,  3 : 6 ] )
194+ 
186195    np .testing .assert_array_equal (
187-         arr [slice (6 , 9 , None ), slice (3 , 6 , None )], a [slice (6 , 9 , None ), slice (3 , 6 , None )]
196+         a [6 :9 , 3 :6 ],
197+         np .frombuffer (
198+             sync (store .get ("2.1" , default_buffer_prototype ())).to_bytes (), dtype = "float64" 
199+         ).reshape ((3 , 3 ), order = array_order ),
188200    )
201+     if  memory_order  ==  "F" :
202+         assert  (arr [6 :9 , 3 :6 ]).flags .f_contiguous 
203+     else :
204+         assert  (arr [6 :9 , 3 :6 ]).flags .c_contiguous 
189205
206+     store  =  MemoryStore ()
190207    arr  =  zarr .create_array (
191-         MemoryStore ({}) ,
208+         store ,
192209        shape = (10 , 8 ),
193210        chunks = (3 , 3 ),
194211        fill_value = np .nan ,
195212        dtype = "float64" ,
196213        zarr_format = 2 ,
214+         compressors = None ,
215+         filters = None ,
197216        overwrite = True ,
198217        order = array_order ,
218+         config = {"order" : memory_order },
199219    )
200220
201221    # Contiguous write 
@@ -204,8 +224,8 @@ def test_v2_non_contiguous(array_order: Literal["C", "F"], data_order: Literal["
204224        assert  a .flags .f_contiguous 
205225    else :
206226        assert  a .flags .c_contiguous 
207-     arr [slice ( 6 ,  9 , None ),  slice ( 3 ,  6 ,  None ) ] =  a 
208-     np .testing .assert_array_equal (arr [slice ( 6 ,  9 , None ),  slice ( 3 ,  6 ,  None ) ], a )
227+     arr [6 : 9 , 3 : 6 ] =  a 
228+     np .testing .assert_array_equal (arr [6 : 9 , 3 : 6 ], a )
209229
210230
211231def  test_default_compressor_deprecation_warning ():
0 commit comments