Skip to content

Commit 9989c64

Browse files
committed
add failing endianness round-trip test
1 parent 40f0063 commit 9989c64

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/test_array.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import re
88
import sys
99
from itertools import accumulate
10-
from typing import TYPE_CHECKING, Any, Literal
10+
from typing import TYPE_CHECKING, Any, Literal, get_args
1111
from unittest import mock
1212

1313
import numcodecs
@@ -39,7 +39,8 @@
3939
from zarr.core.chunk_grids import _auto_partition
4040
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
4141
from zarr.core.dtype import get_data_type_from_native_dtype
42-
from zarr.core.dtype._numpy import Float64
42+
from zarr.core.dtype._numpy import Float64, endianness_from_numpy_str
43+
from zarr.core.dtype.common import Endianness
4344
from zarr.core.dtype.wrapper import ZDType
4445
from zarr.core.group import AsyncGroup
4546
from zarr.core.indexing import BasicIndexer, ceildiv
@@ -1383,3 +1384,20 @@ async def test_sharding_coordinate_selection() -> None:
13831384
)
13841385
arr[:] = np.arange(2 * 3 * 4).reshape((2, 3, 4))
13851386
assert (arr[1, [0, 1]] == np.array([[12, 13, 14, 15], [16, 17, 18, 19]])).all()
1387+
1388+
1389+
@pytest.mark.parametrize("store", ["memory"], indirect=True)
1390+
@pytest.mark.parametrize("endianness", get_args(Endianness))
1391+
def test_endianness(store: Store, zarr_format: ZarrFormat, endianness: Endianness) -> None:
1392+
"""
1393+
Test that that endianness is correctly set when creating an array.
1394+
"""
1395+
if endianness == "little":
1396+
np_dtype = "<i2"
1397+
else:
1398+
np_dtype = ">i2"
1399+
1400+
arr = zarr.create_array(store=store, shape=(1,), dtype=np_dtype, zarr_format=zarr_format)
1401+
assert endianness_from_numpy_str(arr[:].dtype.byteorder) == endianness
1402+
if zarr_format == 3:
1403+
assert str(arr.metadata.codecs[0].endian.value) == endianness

0 commit comments

Comments
 (0)