Skip to content

Commit 24b6b35

Browse files
committed
more v3 unstable dtype warnings, and their exemptions from tests
1 parent cf55041 commit 24b6b35

File tree

8 files changed

+35
-2
lines changed

8 files changed

+35
-2
lines changed

src/zarr/core/dtype/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def v3_unstable_dtype_warning(dtype: object) -> None:
7777
"""
7878
msg = (
7979
f"The data type ({dtype}) does not have a Zarr V3 specification. "
80-
"That means that the representation of data saved with this data type may change without "
80+
"That means that the representation of array saved with this data type may change without "
8181
"warning in a future version of Zarr Python. "
82-
"Arrays stored with this data type may be unreadable by other Zarr libraries "
82+
"Arrays stored with this data type may be unreadable by other Zarr libraries. "
8383
"Use this data type at your own risk! "
8484
"Check https://github.com/zarr-developers/zarr-extensions/tree/main/data-types for the "
8585
"status of data type specifications for Zarr V3."

src/zarr/core/dtype/npy/bytes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def to_json(self, zarr_format: ZarrFormat) -> str | RawBytesJSONV3:
154154
if zarr_format == 2:
155155
return self.to_native_dtype().str
156156
elif zarr_format == 3:
157+
v3_unstable_dtype_warning(self)
157158
return {"name": self._zarr_v3_name, "configuration": {"length_bytes": self.length}}
158159
raise ValueError(f"zarr_format must be 2 or 3, got {zarr_format}") # pragma: no cover
159160

src/zarr/core/dtype/npy/string.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def to_json(self, zarr_format: ZarrFormat) -> Literal["|O", "variable_length_utf
259259
if zarr_format == 2:
260260
return "|O"
261261
elif zarr_format == 3:
262+
v3_unstable_dtype_warning(self)
262263
return self._zarr_v3_name
263264
raise ValueError(f"zarr_format must be 2 or 3, got {zarr_format}") # pragma: no cover
264265

tests/test_array.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ async def test_v2_chunk_encoding(
13001300

13011301
@staticmethod
13021302
@pytest.mark.parametrize("dtype", [UInt8(), Float32(), VariableLengthUTF8()])
1303+
@pytest.mark.filterwarnings("ignore::zarr.core.dtype.common.UnstableSpecificationWarning")
13031304
async def test_default_filters_compressors(
13041305
store: MemoryStore, dtype: UInt8 | Float32 | VariableLengthUTF8, zarr_format: ZarrFormat
13051306
) -> None:

tests/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class NewCodec2(BytesCodec):
306306

307307

308308
@pytest.mark.parametrize("dtype_category", ["variable-length-string", "default"])
309+
@pytest.mark.filterwarnings("ignore::zarr.core.dtype.common.UnstableSpecificationWarning")
309310
async def test_default_codecs(dtype_category: str) -> None:
310311
"""
311312
Test that the default compressors are sensitive to the current setting of the config.

tests/test_dtype/test_npy/test_bytes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import numpy as np
2+
import pytest
23

34
from tests.test_dtype.test_wrapper import BaseTestZDType, V2JsonTestParams
5+
from zarr.core.dtype.common import UnstableSpecificationWarning
46
from zarr.core.dtype.npy.bytes import NullTerminatedBytes, RawBytes, VariableLengthBytes
57

68

@@ -136,3 +138,17 @@ class TestVariableLengthBytes(BaseTestZDType):
136138
VariableLengthBytes(),
137139
VariableLengthBytes(),
138140
)
141+
142+
143+
@pytest.mark.parametrize(
144+
"zdtype", [NullTerminatedBytes(length=10), RawBytes(length=10), VariableLengthBytes()]
145+
)
146+
def test_unstable_dtype_warning(
147+
zdtype: NullTerminatedBytes | RawBytes | VariableLengthBytes,
148+
) -> None:
149+
"""
150+
Test that we get a warning when serializing a dtype without a zarr v3 spec to json
151+
when zarr_format is 3
152+
"""
153+
with pytest.raises(UnstableSpecificationWarning):
154+
zdtype.to_json(zarr_format=3)

tests/test_dtype/test_npy/test_string.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

33
import numpy as np
4+
import pytest
45

56
from tests.test_dtype.test_wrapper import BaseTestZDType, V2JsonTestParams
67
from zarr.core.dtype import FixedLengthUTF32
8+
from zarr.core.dtype.common import UnstableSpecificationWarning
79
from zarr.core.dtype.npy.string import _NUMPY_SUPPORTS_VLEN_STRING, VariableLengthUTF8
810

911
if _NUMPY_SUPPORTS_VLEN_STRING:
@@ -113,3 +115,13 @@ class TestFixedLengthUTF32(BaseTestZDType):
113115
FixedLengthUTF32(length=4),
114116
FixedLengthUTF32(length=10),
115117
)
118+
119+
120+
@pytest.mark.parametrize("zdtype", [FixedLengthUTF32(length=10), VariableLengthUTF8()])
121+
def test_unstable_dtype_warning(zdtype: FixedLengthUTF32 | VariableLengthUTF8) -> None:
122+
"""
123+
Test that we get a warning when serializing a dtype without a zarr v3 spec to json
124+
when zarr_format is 3
125+
"""
126+
with pytest.raises(UnstableSpecificationWarning):
127+
zdtype.to_json(zarr_format=3)

tests/test_store/test_stateful.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
]
1616

1717

18+
@pytest.mark.filterwarnings("ignore::zarr.core.dtype.common.UnstableSpecificationWarning")
1819
def test_zarr_hierarchy(sync_store: Store):
1920
def mk_test_instance_sync() -> ZarrHierarchyStateMachine:
2021
return ZarrHierarchyStateMachine(sync_store)

0 commit comments

Comments
 (0)