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
@@ -297,31 +296,28 @@ def arrays(
297296 # - RectilinearChunkGridMetadata -> nested list of ints (triggers rectilinear path)
298297 # - v2 -> flat tuple of ints
299298 chunks_param : tuple [int , ...] | list [list [int ]]
300- use_rectilinear = False
301299 if zarr_format == 3 and chunk_grid_meta is not None :
302300 if isinstance (chunk_grid_meta , RectilinearChunkGridMetadata ):
303301 chunks_param = [
304302 list (dim ) if isinstance (dim , tuple ) else [dim ]
305303 for dim in chunk_grid_meta .chunk_shapes
306304 ]
307- use_rectilinear = True
308305 else :
309306 chunks_param = chunk_grid_meta .chunk_shape
310307 else :
311308 chunks_param = draw (chunk_shapes (shape = nparray .shape ), label = "chunk shape" )
312309
313- with zarr .config .set ({"array.rectilinear_chunks" : True }) if use_rectilinear else nullcontext ():
314- a = root .create_array (
315- array_path ,
316- shape = nparray .shape ,
317- chunks = chunks_param ,
318- shards = shard_shape ,
319- dtype = nparray .dtype ,
320- attributes = attributes ,
321- # compressor=compressor, # FIXME
322- fill_value = fill_value ,
323- dimension_names = dim_names ,
324- )
310+ a = root .create_array (
311+ array_path ,
312+ shape = nparray .shape ,
313+ chunks = chunks_param ,
314+ shards = shard_shape ,
315+ dtype = nparray .dtype ,
316+ attributes = attributes ,
317+ # compressor=compressor, # FIXME
318+ fill_value = fill_value ,
319+ dimension_names = dim_names ,
320+ )
325321
326322 assert isinstance (a , Array )
327323 if a .metadata .zarr_format == 3 :
@@ -427,6 +423,10 @@ def chunk_grids(
427423) -> RegularChunkGridMetadata | RectilinearChunkGridMetadata :
428424 """Generate either a RegularChunkGridMetadata or RectilinearChunkGridMetadata.
429425
426+ This strategy depends on the global state of the config having rectilinear chunk grids enabled or not.
427+ This means that it may be a possible source of a hypothesis FlakyStrategy error due dependence
428+ on global state. However, in practice this seems unlikely to happen.
429+
430430 This allows property tests to exercise both chunk grid types.
431431 """
432432 # RectilinearChunkGridMetadata doesn't support zero-sized dimensions,
@@ -435,11 +435,10 @@ def chunk_grids(
435435 event ("using RegularChunkGridMetadata (zero-sized dimensions)" )
436436 return RegularChunkGridMetadata (chunk_shape = draw (chunk_shapes (shape = shape )))
437437
438- if draw (st .booleans ()):
438+ if zarr . config . get ( "array.rectilinear_chunks" ) and draw (st .booleans ()):
439439 chunks = draw (rectilinear_chunks (shape = shape ))
440440 event ("using RectilinearChunkGridMetadata" )
441- with zarr .config .set ({"array.rectilinear_chunks" : True }):
442- return RectilinearChunkGridMetadata (chunk_shapes = tuple (tuple (dim ) for dim in chunks ))
441+ return RectilinearChunkGridMetadata (chunk_shapes = tuple (tuple (dim ) for dim in chunks ))
443442 else :
444443 event ("using RegularChunkGridMetadata" )
445444 return RegularChunkGridMetadata (chunk_shape = draw (chunk_shapes (shape = shape )))
0 commit comments