Skip to content

Commit e3ee591

Browse files
authored
Fix: allow "bytes" as an alias for "variable_length_bytes" (#3532)
* add bytes alias for VariableLengthBytes * make alias test stand-alone * changelog
1 parent 7fe95b5 commit e3ee591

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

changes/3532.misc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Accept `"bytes"` as an alias for `"variable_length_bytes"` when parsing `JSON`-encoded Zarr V3
2+
data types.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def _check_json_v3(cls, data: DTypeJSON) -> TypeGuard[Literal["variable_length_b
10461046
True if the input is a valid representation of this class in Zarr V3, False otherwise.
10471047
"""
10481048

1049-
return data == cls._zarr_v3_name
1049+
return data in (cls._zarr_v3_name, "bytes")
10501050

10511051
@classmethod
10521052
def _from_json_v2(cls, data: DTypeJSON) -> Self:

tests/test_dtype/test_npy/test_bytes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ class TestVariableLengthBytes(BaseTestZDType):
140140
item_size_params = (VariableLengthBytes(),)
141141

142142

143+
def test_vlen_bytes_alias() -> None:
144+
"""Test that "bytes" is an accepted alias for "variable_length_bytes" in JSON metadata"""
145+
a = VariableLengthBytes.from_json("bytes", zarr_format=3)
146+
b = VariableLengthBytes.from_json("variable_length_bytes", zarr_format=3)
147+
assert a == b
148+
149+
143150
@pytest.mark.parametrize(
144151
"zdtype", [NullTerminatedBytes(length=10), RawBytes(length=10), VariableLengthBytes()]
145152
)

0 commit comments

Comments
 (0)