From e022f925fa9f0417460abb247c170d18c334fcda Mon Sep 17 00:00:00 2001 From: Iason Krommydas Date: Mon, 22 Sep 2025 22:11:19 +0200 Subject: [PATCH] make most tests pass on big-endian --- src/awkward/_do.py | 2 +- src/awkward/_pickle.py | 5 +++-- src/awkward/contents/numpyarray.py | 6 +++--- src/awkward/highlevel.py | 10 +++++----- src/awkward/operations/ak_from_buffers.py | 3 ++- tests/test_2067_to_buffers_byteorder.py | 2 +- tests/test_2198_almost_equal.py | 8 ++++---- tests/test_2305_nep_18_lazy_conversion.py | 5 +++-- tests/test_2424_almost_equal_union_record.py | 8 ++++---- tests/test_2857_full_like_scalar.py | 4 ++-- 10 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/awkward/_do.py b/src/awkward/_do.py index 014d3c53c3..b021e628bb 100644 --- a/src/awkward/_do.py +++ b/src/awkward/_do.py @@ -78,7 +78,7 @@ def to_buffers( form_key: str | None = "node{id}", id_start: Integral = 0, backend: Backend | None = None, - byteorder: Literal["<", ">"] = "<", + byteorder: Literal["<", ">"] = ak._util.native_byteorder, ) -> tuple[form.Form, int, Mapping[str, Any]]: if container is None: container = {} diff --git a/src/awkward/_pickle.py b/src/awkward/_pickle.py index 41449f4d28..d384b84f68 100644 --- a/src/awkward/_pickle.py +++ b/src/awkward/_pickle.py @@ -10,6 +10,7 @@ from collections.abc import Mapping from contextlib import contextmanager +import awkward as ak from awkward._typing import TYPE_CHECKING, Any, JSONMapping, Protocol, runtime_checkable if sys.version_info < (3, 12): @@ -113,7 +114,7 @@ def unpickle_array_schema_1( attrs=attrs, highlevel=True, buffer_key="{form_key}-{attribute}", - byteorder="<", + byteorder=ak._util.native_byteorder, simplify=False, ) @@ -139,7 +140,7 @@ def unpickle_record_schema_1( attrs=attrs, highlevel=False, buffer_key="{form_key}-{attribute}", - byteorder="<", + byteorder=ak._util.native_byteorder, simplify=False, ) layout = LowLevelRecord(array_layout, at) diff --git a/src/awkward/contents/numpyarray.py b/src/awkward/contents/numpyarray.py index 19e1271202..73e60e9117 100644 --- a/src/awkward/contents/numpyarray.py +++ b/src/awkward/contents/numpyarray.py @@ -588,7 +588,7 @@ def is_contiguous(self) -> bool: return self._backend.nplike.is_c_contiguous(self._data) def _subranges_equal(self, starts, stops, length, sorted=True): - is_equal = ak.index.Index64.zeros(1, nplike=self._backend.nplike) + is_equal = self._backend.nplike.zeros(1, dtype=np.bool_) assert ( starts.nplike is self._backend.nplike @@ -609,7 +609,7 @@ def _subranges_equal(self, starts, stops, length, sorted=True): starts.data, stops.data, starts.length, - is_equal.data, + is_equal, ) ) else: @@ -627,7 +627,7 @@ def _subranges_equal(self, starts, stops, length, sorted=True): starts.data, stops.data, starts.length, - is_equal.data, + is_equal, ) ) diff --git a/src/awkward/highlevel.py b/src/awkward/highlevel.py index 87d3f5693e..1d08d244d1 100644 --- a/src/awkward/highlevel.py +++ b/src/awkward/highlevel.py @@ -1675,7 +1675,7 @@ def __reduce_ex__(self, protocol: int) -> tuple: packed_layout, buffer_key="{form_key}-{attribute}", form_key="node{id}", - byteorder="<", + byteorder=ak._util.native_byteorder, ) # For pickle >= 5, we can avoid copying the buffers @@ -1712,7 +1712,7 @@ def __setstate__(self, state): container, highlevel=False, buffer_key="{form_key}-{attribute}", - byteorder="<", + byteorder=ak._util.native_byteorder, ) for i, part_length in enumerate(length) ] @@ -1727,7 +1727,7 @@ def __setstate__(self, state): container, highlevel=False, buffer_key="{form_key}-{attribute}", - byteorder="<", + byteorder=ak._util.native_byteorder, ) self._layout = layout self._behavior = behavior @@ -2509,7 +2509,7 @@ def __reduce_ex__(self, protocol: int) -> tuple: packed_layout.array, buffer_key="{form_key}-{attribute}", form_key="node{id}", - byteorder="<", + byteorder=ak._util.native_byteorder, ) # For pickle >= 5, we can avoid copying the buffers @@ -2544,7 +2544,7 @@ def __setstate__(self, state): container, highlevel=False, buffer_key="{form_key}-{attribute}", - byteorder="<", + byteorder=ak._util.native_byteorder, ) layout = ak.record.Record(layout, at) self._layout = layout diff --git a/src/awkward/operations/ak_from_buffers.py b/src/awkward/operations/ak_from_buffers.py index e06fc1a68d..7128c4e0d5 100644 --- a/src/awkward/operations/ak_from_buffers.py +++ b/src/awkward/operations/ak_from_buffers.py @@ -34,7 +34,7 @@ def from_buffers( buffer_key="{form_key}-{attribute}", *, backend="cpu", - byteorder="<", + byteorder=ak._util.native_byteorder, allow_noncanonical_form=False, highlevel=True, behavior=None, @@ -235,6 +235,7 @@ def generator(): # Require 1D buffers copy = None if isinstance(nplike, Jax) else False # Jax can not avoid this array = nplike.reshape(buffer.view(dtype), shape=(-1,), copy=copy) + array = ak._util.native_to_byteorder(array, byteorder) # we can't compare with count or slice when we're working with tracers if not (isinstance(nplike, Jax) and nplike.is_currently_tracing()): diff --git a/tests/test_2067_to_buffers_byteorder.py b/tests/test_2067_to_buffers_byteorder.py index e9ba029640..7dc867540e 100644 --- a/tests/test_2067_to_buffers_byteorder.py +++ b/tests/test_2067_to_buffers_byteorder.py @@ -20,7 +20,7 @@ def test_byteorder(): def test_byteorder_default(): array = ak.Array([[[1, 2, 3], [4, 5], None, "hi"]]) - _, _, container_little = ak.to_buffers(array, byteorder="<") + _, _, container_little = ak.to_buffers(array, byteorder=ak._util.native_byteorder) _, _, container_default = ak.to_buffers(array) for name, buffer in container_little.items(): diff --git a/tests/test_2198_almost_equal.py b/tests/test_2198_almost_equal.py index d791e93c22..7f03c7afdd 100644 --- a/tests/test_2198_almost_equal.py +++ b/tests/test_2198_almost_equal.py @@ -27,13 +27,13 @@ def test_dtype(): dtype_exact=True, ) assert not ak.almost_equal( - np.array([1, 2, 3], dtype=np.dtype("