|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import sys |
| 4 | +import warnings |
4 | 5 | from dataclasses import dataclass, replace |
5 | 6 | from enum import Enum |
6 | 7 | from typing import TYPE_CHECKING |
|
9 | 10 | from zarr.core.buffer import Buffer, NDBuffer |
10 | 11 | from zarr.core.common import JSON, parse_enum, parse_named_configuration |
11 | 12 | from zarr.core.dtype.common import HasEndianness |
| 13 | +from zarr.core.dtype.npy.structured import Struct |
12 | 14 |
|
13 | 15 | if TYPE_CHECKING: |
14 | 16 | from typing import Self |
@@ -56,7 +58,20 @@ def to_dict(self) -> dict[str, JSON]: |
56 | 58 | return {"name": "bytes", "configuration": {"endian": self.endian.value}} |
57 | 59 |
|
58 | 60 | def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self: |
59 | | - if not isinstance(array_spec.dtype, HasEndianness): |
| 61 | + if isinstance(array_spec.dtype, Struct): |
| 62 | + if array_spec.dtype.has_multi_byte_fields(): |
| 63 | + if self.endian is None: |
| 64 | + warnings.warn( |
| 65 | + "Missing 'endian' for structured dtype with multi-byte fields. " |
| 66 | + "Assuming little-endian for legacy compatibility.", |
| 67 | + UserWarning, |
| 68 | + stacklevel=2, |
| 69 | + ) |
| 70 | + return replace(self, endian=Endian.little) |
| 71 | + else: |
| 72 | + if self.endian is not None: |
| 73 | + return replace(self, endian=None) |
| 74 | + elif not isinstance(array_spec.dtype, HasEndianness): |
60 | 75 | if self.endian is not None: |
61 | 76 | return replace(self, endian=None) |
62 | 77 | elif self.endian is None: |
|
0 commit comments