12
12
import zarr .core .buffer
13
13
import zarr .storage
14
14
from zarr import config
15
+ from zarr .core .buffer .core import default_buffer_prototype
16
+ from zarr .core .sync import sync
15
17
from zarr .storage import MemoryStore , StorePath
16
18
17
19
@@ -166,36 +168,54 @@ def test_v2_filters_codecs(filters: Any, order: Literal["C", "F"]) -> None:
166
168
167
169
@pytest .mark .parametrize ("array_order" , ["C" , "F" ])
168
170
@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 ()
170
176
arr = zarr .create_array (
171
- MemoryStore ({}) ,
177
+ store ,
172
178
shape = (10 , 8 ),
173
179
chunks = (3 , 3 ),
174
180
fill_value = np .nan ,
175
181
dtype = "float64" ,
176
182
zarr_format = 2 ,
183
+ filters = None ,
184
+ compressors = None ,
177
185
overwrite = True ,
178
186
order = array_order ,
187
+ config = {"order" : memory_order },
179
188
)
180
189
181
190
# Non-contiguous write
182
191
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
+
186
195
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 ),
188
200
)
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
189
205
206
+ store = MemoryStore ()
190
207
arr = zarr .create_array (
191
- MemoryStore ({}) ,
208
+ store ,
192
209
shape = (10 , 8 ),
193
210
chunks = (3 , 3 ),
194
211
fill_value = np .nan ,
195
212
dtype = "float64" ,
196
213
zarr_format = 2 ,
214
+ compressors = None ,
215
+ filters = None ,
197
216
overwrite = True ,
198
217
order = array_order ,
218
+ config = {"order" : memory_order },
199
219
)
200
220
201
221
# Contiguous write
@@ -204,8 +224,8 @@ def test_v2_non_contiguous(array_order: Literal["C", "F"], data_order: Literal["
204
224
assert a .flags .f_contiguous
205
225
else :
206
226
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 )
209
229
210
230
211
231
def test_default_compressor_deprecation_warning ():
0 commit comments