Skip to content

Commit 617d3f0

Browse files
committed
relax endianness mismatch to a warning instead of an error
1 parent aa32271 commit 617d3f0

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/zarr/core/array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4382,9 +4382,9 @@ def _parse_chunk_encoding_v3(
43824382
):
43834383
msg = (
43844384
f"The endianness of the requested serializer ({out_array_bytes}) does not match the endianness of the dtype ({dtype.endianness}). "
4385-
"The endianness of the serializer and the dtype must match."
4385+
"In this situation the serializer's endianness takes priority. To avoid this warning, ensure the endianness of the serializer matches the endianness of the dtype."
43864386
)
4387-
raise ValueError(msg)
4387+
warnings.warn(msg, UserWarning, stacklevel=2)
43884388

43894389
if compressors is None:
43904390
out_bytes_bytes: tuple[BytesBytesCodec, ...] = ()

tests/test_array.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,10 +1349,11 @@ def test_explicit_endianness(store: Store, endianness: Endianness) -> None:
13491349

13501350
msg = (
13511351
f"The endianness of the requested serializer ({serializer}) does not match the endianness of the dtype ({dtype.endianness}). "
1352-
"The endianness of the serializer and the dtype must match."
1352+
"In this situation the serializer's endianness takes priority. "
1353+
"To avoid this warning, ensure the endianness of the serializer matches the endianness of the dtype."
13531354
)
13541355

1355-
with pytest.raises(ValueError, match=re.escape(msg)):
1356+
with pytest.warns(UserWarning, match=re.escape(msg)):
13561357
_ = zarr.create_array(
13571358
store=store,
13581359
shape=(1,),
@@ -1361,22 +1362,6 @@ def test_explicit_endianness(store: Store, endianness: Endianness) -> None:
13611362
serializer=serializer,
13621363
)
13631364

1364-
# additional check for the case where the serializer has endian=None
1365-
none_serializer = dataclasses.replace(serializer, endian=None)
1366-
msg = (
1367-
f"The endianness of the requested serializer ({none_serializer}) does not match the endianness of the dtype ({dtype.endianness}). "
1368-
"The endianness of the serializer and the dtype must match."
1369-
)
1370-
1371-
with pytest.raises(ValueError, match=re.escape(msg)):
1372-
_ = zarr.create_array(
1373-
store=store,
1374-
shape=(1,),
1375-
dtype=dtype,
1376-
zarr_format=3,
1377-
serializer=none_serializer,
1378-
)
1379-
13801365

13811366
async def test_scalar_array() -> None:
13821367
arr = zarr.array(1.5)

tests/test_codecs/test_endian.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .test_codecs import _AsyncArrayProxy
1212

1313

14+
@pytest.mark.filterwarnings("ignore:The endianness of the requested serializer")
1415
@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
1516
@pytest.mark.parametrize("endian", ["big", "little"])
1617
async def test_endian(store: Store, endian: Literal["big", "little"]) -> None:
@@ -32,6 +33,7 @@ async def test_endian(store: Store, endian: Literal["big", "little"]) -> None:
3233
assert np.array_equal(data, readback_data)
3334

3435

36+
@pytest.mark.filterwarnings("ignore:The endianness of the requested serializer")
3537
@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"])
3638
@pytest.mark.parametrize("dtype_input_endian", [">u2", "<u2"])
3739
@pytest.mark.parametrize("dtype_store_endian", ["big", "little"])

0 commit comments

Comments
 (0)