|
7 | 7 | import re |
8 | 8 | import sys |
9 | 9 | from itertools import accumulate |
10 | | -from typing import TYPE_CHECKING, Any, Literal |
| 10 | +from typing import TYPE_CHECKING, Any, Literal, get_args |
11 | 11 | from unittest import mock |
12 | 12 |
|
13 | 13 | import numcodecs |
|
39 | 39 | from zarr.core.chunk_grids import _auto_partition |
40 | 40 | from zarr.core.common import JSON, MemoryOrder, ZarrFormat |
41 | 41 | 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 |
43 | 44 | from zarr.core.dtype.wrapper import ZDType |
44 | 45 | from zarr.core.group import AsyncGroup |
45 | 46 | from zarr.core.indexing import BasicIndexer, ceildiv |
@@ -1383,3 +1384,20 @@ async def test_sharding_coordinate_selection() -> None: |
1383 | 1384 | ) |
1384 | 1385 | arr[:] = np.arange(2 * 3 * 4).reshape((2, 3, 4)) |
1385 | 1386 | 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