11import math
22import sys
33from collections .abc import Callable , Mapping
4- from contextlib import nullcontext
54from typing import Any , Literal
65
76import hypothesis .extra .numpy as npst
@@ -296,31 +295,28 @@ def arrays(
296295 # - RectilinearChunkGridMetadata -> nested list of ints (triggers rectilinear path)
297296 # - v2 -> flat tuple of ints
298297 chunks_param : tuple [int , ...] | list [list [int ]]
299- use_rectilinear = False
300298 if zarr_format == 3 and chunk_grid_meta is not None :
301299 if isinstance (chunk_grid_meta , RectilinearChunkGridMetadata ):
302300 chunks_param = [
303301 list (dim ) if isinstance (dim , tuple ) else [dim ]
304302 for dim in chunk_grid_meta .chunk_shapes
305303 ]
306- use_rectilinear = True
307304 else :
308305 chunks_param = chunk_grid_meta .chunk_shape
309306 else :
310307 chunks_param = draw (chunk_shapes (shape = nparray .shape ), label = "chunk shape" )
311308
312- with zarr .config .set ({"array.rectilinear_chunks" : True }) if use_rectilinear else nullcontext ():
313- a = root .create_array (
314- array_path ,
315- shape = nparray .shape ,
316- chunks = chunks_param ,
317- shards = shard_shape ,
318- dtype = nparray .dtype ,
319- attributes = attributes ,
320- # compressor=compressor, # FIXME
321- fill_value = fill_value ,
322- dimension_names = dim_names ,
323- )
309+ a = root .create_array (
310+ array_path ,
311+ shape = nparray .shape ,
312+ chunks = chunks_param ,
313+ shards = shard_shape ,
314+ dtype = nparray .dtype ,
315+ attributes = attributes ,
316+ # compressor=compressor, # FIXME
317+ fill_value = fill_value ,
318+ dimension_names = dim_names ,
319+ )
324320
325321 assert isinstance (a , Array )
326322 if a .metadata .zarr_format == 3 :
@@ -426,6 +422,10 @@ def chunk_grids(
426422) -> RegularChunkGridMetadata | RectilinearChunkGridMetadata :
427423 """Generate either a RegularChunkGridMetadata or RectilinearChunkGridMetadata.
428424
425+ This strategy depends on the global state of the config having rectilinear chunk grids enabled or not.
426+ This means that it may be a possible source of a hypothesis FlakyStrategy error due dependence
427+ on global state. However, in practice this seems unlikely to happen.
428+
429429 This allows property tests to exercise both chunk grid types.
430430 """
431431 # RectilinearChunkGridMetadata doesn't support zero-sized dimensions,
@@ -434,11 +434,10 @@ def chunk_grids(
434434 event ("using RegularChunkGridMetadata (zero-sized dimensions)" )
435435 return RegularChunkGridMetadata (chunk_shape = draw (chunk_shapes (shape = shape )))
436436
437- if draw (st .booleans ()):
437+ if zarr . config . get ( "array.rectilinear_chunks" ) and draw (st .booleans ()):
438438 chunks = draw (rectilinear_chunks (shape = shape ))
439439 event ("using RectilinearChunkGridMetadata" )
440- with zarr .config .set ({"array.rectilinear_chunks" : True }):
441- return RectilinearChunkGridMetadata (chunk_shapes = tuple (tuple (dim ) for dim in chunks ))
440+ return RectilinearChunkGridMetadata (chunk_shapes = tuple (tuple (dim ) for dim in chunks ))
442441 else :
443442 event ("using RegularChunkGridMetadata" )
444443 return RegularChunkGridMetadata (chunk_shape = draw (chunk_shapes (shape = shape )))
0 commit comments