Skip to content

Commit 1fb9ca4

Browse files
committed
test: require a ZDType in _make_spec instead of a dtype string
Assisted-by: ClaudeCode:claude-fable-5
1 parent 6a9dd4b commit 1fb9ca4

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

tests/test_fused_pipeline.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from zarr.core.chunk_utils import ChunkTransform, evolve_codecs
3030
from zarr.core.codec_pipeline import AsyncChunkTransform, FusedCodecPipeline
3131
from zarr.core.config import config as zarr_config
32-
from zarr.core.dtype import get_data_type_from_native_dtype
32+
from zarr.core.dtype import Float32, Float64, Int32, UInt8, ZDType
3333
from zarr.registry import register_codec
3434
from zarr.storage import MemoryStore, StorePath, WrapperStore
3535
from zarr.storage._utils import _normalize_byte_range_index
@@ -42,16 +42,18 @@
4242
from zarr.core.buffer import Buffer, NDBuffer
4343

4444

45+
_FLOAT64 = Float64()
46+
47+
4548
def _make_spec(
4649
shape: tuple[int, ...],
47-
dtype: str = "float64",
50+
zdtype: ZDType[Any, Any] = _FLOAT64,
4851
fill_value: float = 0,
4952
*,
5053
write_empty_chunks: bool = True,
5154
prototype: BufferPrototype | None = None,
5255
) -> ArraySpec:
5356
"""An ArraySpec with the C-order defaults shared by the tests in this file."""
54-
zdtype = get_data_type_from_native_dtype(np.dtype(dtype))
5557
return ArraySpec(
5658
shape=shape,
5759
dtype=zdtype,
@@ -156,19 +158,20 @@ def test_evolve_from_array_spec() -> None:
156158

157159

158160
@pytest.mark.parametrize(
159-
("dtype", "shape"),
161+
("zdtype", "shape"),
160162
[
161-
("float64", (100,)),
162-
("float32", (50,)),
163-
("int32", (200,)),
164-
("float64", (10, 10)),
163+
(Float64(), (100,)),
164+
(Float32(), (50,)),
165+
(Int32(), (200,)),
166+
(Float64(), (10, 10)),
165167
],
166168
ids=["f64-1d", "f32-1d", "i32-1d", "f64-2d"],
167169
)
168-
def test_read_write_sync_roundtrip(dtype: str, shape: tuple[int, ...]) -> None:
170+
def test_read_write_sync_roundtrip(zdtype: ZDType[Any, Any], shape: tuple[int, ...]) -> None:
169171
"""Data written via write_sync can be read back via read_sync."""
170172
store = MemoryStore()
171-
spec = _make_spec(shape, dtype)
173+
dtype = zdtype.to_native_dtype()
174+
spec = _make_spec(shape, zdtype)
172175

173176
pipeline = FusedCodecPipeline.from_codecs((BytesCodec(),))
174177
pipeline = pipeline.evolve_from_array_spec(spec)
@@ -469,7 +472,7 @@ async def delete(self) -> None:
469472
async def set_if_not_exists(self, default: Buffer) -> None:
470473
pass
471474

472-
chunk_spec = _make_spec((1,), "uint8")
475+
chunk_spec = _make_spec((1,), UInt8())
473476
chunk_array = CPUNDBuffer.from_numpy_array(np.zeros(1, dtype="uint8"))
474477
transform = ChunkTransform(codecs=(BytesCodec(),))
475478

@@ -548,7 +551,7 @@ def test_shared_transform_decode_alternating_specs() -> None:
548551
# two distinct specs (different shapes) sharing the one transform + cache slot
549552
cases = []
550553
for shape in [(5, 7), (3, 11)]:
551-
spec = _make_spec(shape, "int32")
554+
spec = _make_spec(shape, Int32())
552555
arr = np.arange(int(np.prod(shape)), dtype="int32").reshape(shape)
553556
encoded = transform.encode_chunk(CPUNDBuffer.from_numpy_array(arr), spec)
554557
assert encoded is not None
@@ -642,7 +645,7 @@ def test_write_over_sync_byte_setter_takes_sync_path() -> None:
642645
"""
643646
from zarr.codecs.sharding import _ShardingByteSetter
644647

645-
spec = _make_spec((10,), "uint8")
648+
spec = _make_spec((10,), UInt8())
646649
pipeline = FusedCodecPipeline.from_codecs([BytesCodec()]).evolve_from_array_spec(spec)
647650
assert pipeline.sync_transform is not None
648651

@@ -815,7 +818,7 @@ def test_async_chunk_transform_matches_sync(
815818
touches.
816819
"""
817820
shape = (4, 4)
818-
spec = _make_spec(shape, "int32")
821+
spec = _make_spec(shape, Int32())
819822
evolved = evolve_codecs(case.input, spec)
820823
sync_t = ChunkTransform(codecs=evolved)
821824
async_t = AsyncChunkTransform(codecs=evolved)
@@ -839,7 +842,7 @@ def test_async_decode_encode_passes_through_none_chunks() -> None:
839842
"""`FusedCodecPipeline.decode`/`encode` (the async batch entry points used
840843
on the fallback path) map a None chunk to None and leave real chunks
841844
untouched — pins the None-passthrough branch the default sync path skips."""
842-
spec = _make_spec((4,), "int32")
845+
spec = _make_spec((4,), Int32())
843846
pipeline = FusedCodecPipeline.from_codecs([BytesCodec()]).evolve_from_array_spec(spec)
844847

845848
data = np.arange(4, dtype="int32")

0 commit comments

Comments
 (0)