Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/zarr/testing/strategies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math
import sys
from collections.abc import Callable, Mapping
from contextlib import nullcontext
from typing import Any, Literal

import hypothesis.extra.numpy as npst
Expand Down Expand Up @@ -297,31 +296,28 @@ def arrays(
# - RectilinearChunkGridMetadata -> nested list of ints (triggers rectilinear path)
# - v2 -> flat tuple of ints
chunks_param: tuple[int, ...] | list[list[int]]
use_rectilinear = False
if zarr_format == 3 and chunk_grid_meta is not None:
if isinstance(chunk_grid_meta, RectilinearChunkGridMetadata):
chunks_param = [
list(dim) if isinstance(dim, tuple) else [dim]
for dim in chunk_grid_meta.chunk_shapes
]
use_rectilinear = True
else:
chunks_param = chunk_grid_meta.chunk_shape
else:
chunks_param = draw(chunk_shapes(shape=nparray.shape), label="chunk shape")

with zarr.config.set({"array.rectilinear_chunks": True}) if use_rectilinear else nullcontext():
a = root.create_array(
array_path,
shape=nparray.shape,
chunks=chunks_param,
shards=shard_shape,
dtype=nparray.dtype,
attributes=attributes,
# compressor=compressor, # FIXME
fill_value=fill_value,
dimension_names=dim_names,
)
a = root.create_array(
array_path,
shape=nparray.shape,
chunks=chunks_param,
shards=shard_shape,
dtype=nparray.dtype,
attributes=attributes,
# compressor=compressor, # FIXME
fill_value=fill_value,
dimension_names=dim_names,
)

assert isinstance(a, Array)
if a.metadata.zarr_format == 3:
Expand Down Expand Up @@ -426,6 +422,7 @@ def chunk_grids(
draw: st.DrawFn, *, shape: tuple[int, ...]
) -> RegularChunkGridMetadata | RectilinearChunkGridMetadata:
"""Generate either a RegularChunkGridMetadata or RectilinearChunkGridMetadata.
Depending on whether the config is set (WARN: look here if we get a flaky error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was all me - so any confusion is my fault.

This makes this strategy dependent on global state, i.e. a recipe for a flaky strategy down the line. I wanted to leave a note for the future in case that happens. Don't think I really hit the mark here though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok let's write in a longer comment then :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Depending on whether the config is set (WARN: look here if we get a flaky error)
This strategy depends on the global state of the config having rectilinear chunk grids enabled or not.
This means that it may be a possible source of a hypothesis FlakyStrategy error due dependence
on global state. However, in practice this seems unlikely to happen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcherian how is that?


This allows property tests to exercise both chunk grid types.
"""
Expand All @@ -435,11 +432,10 @@ def chunk_grids(
event("using RegularChunkGridMetadata (zero-sized dimensions)")
return RegularChunkGridMetadata(chunk_shape=draw(chunk_shapes(shape=shape)))

if draw(st.booleans()):
if zarr.config.get("array.rectilinear_chunks") and draw(st.booleans()):
chunks = draw(rectilinear_chunks(shape=shape))
event("using RectilinearChunkGridMetadata")
with zarr.config.set({"array.rectilinear_chunks": True}):
return RectilinearChunkGridMetadata(chunk_shapes=tuple(tuple(dim) for dim in chunks))
return RectilinearChunkGridMetadata(chunk_shapes=tuple(tuple(dim) for dim in chunks))
else:
event("using RegularChunkGridMetadata")
return RegularChunkGridMetadata(chunk_shape=draw(chunk_shapes(shape=shape)))
Expand Down
Loading