Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/awkward/_do.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
5 changes: 3 additions & 2 deletions src/awkward/_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
)

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/awkward/contents/numpyarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -627,7 +627,7 @@ def _subranges_equal(self, starts, stops, length, sorted=True):
starts.data,
stops.data,
starts.length,
is_equal.data,
is_equal,
)
)

Expand Down
10 changes: 5 additions & 5 deletions src/awkward/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/awkward/operations/ak_from_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_2067_to_buffers_byteorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_2198_almost_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def test_dtype():
dtype_exact=True,
)
assert not ak.almost_equal(
np.array([1, 2, 3], dtype=np.dtype("<M8[D]")),
np.array([1, 2, 3], dtype=np.dtype("<m8[D]")),
np.array([1, 2, 3], dtype=np.dtype("M8[D]")),
np.array([1, 2, 3], dtype=np.dtype("m8[D]")),
dtype_exact=True,
)
assert not ak.almost_equal(
np.array([1, 2, 3], dtype=np.dtype("<M8[D]")),
np.array([1, 2, 3], dtype=np.dtype("<m8[D]")),
np.array([1, 2, 3], dtype=np.dtype("M8[D]")),
np.array([1, 2, 3], dtype=np.dtype("m8[D]")),
dtype_exact=False,
)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_2305_nep_18_lazy_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@


def test_binary():
ak_array = ak.Array(np.arange(10, dtype="<u4"))
np_array = np.arange(10, dtype=">u4")
dtype = np.dtype("u4")
ak_array = ak.Array(np.arange(10, dtype=dtype))
np_array = np.arange(10, dtype=dtype.newbyteorder("S"))
with pytest.raises(TypeError):
# ak.array_equal now overrides np.array_equal, and requires
# both arrays to be valid within awkward.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_2424_almost_equal_union_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def test_records_almost_equal():
first = ak.contents.RecordArray(
[
ak.contents.NumpyArray(np.array([1, 2, 3], dtype=np.int64)),
ak.contents.NumpyArray(np.array([0], dtype=np.dtype("<M8[s]"))),
ak.contents.NumpyArray(np.array([0], dtype=np.dtype("M8[s]"))),
],
["x", "y"],
)

second = ak.contents.RecordArray(
[
ak.contents.NumpyArray(np.array([0], dtype=np.dtype("<M8[s]"))),
ak.contents.NumpyArray(np.array([0], dtype=np.dtype("M8[s]"))),
ak.contents.NumpyArray(np.array([1, 2, 3], dtype=np.int64)),
],
["y", "x"],
Expand All @@ -35,7 +35,7 @@ def test_unions_almost_equal():
ak.index.Index64([0, 1, 0, 0, 1]),
[
ak.contents.NumpyArray(np.array([1, 2, 3], dtype=np.int64)),
ak.contents.NumpyArray(np.array([0, 1], dtype=np.dtype("<M8[s]"))),
ak.contents.NumpyArray(np.array([0, 1], dtype=np.dtype("M8[s]"))),
ak.contents.NumpyArray(np.array([0, 1, 0, 1], dtype=np.bool_)),
],
)
Expand All @@ -45,7 +45,7 @@ def test_unions_almost_equal():
[
ak.contents.NumpyArray(np.array([0, 1, 0, 1], dtype=np.bool_)),
ak.contents.NumpyArray(np.array([1, 2, 3], dtype=np.int64)),
ak.contents.NumpyArray(np.array([0, 1], dtype=np.dtype("<M8[s]"))),
ak.contents.NumpyArray(np.array([0, 1], dtype=np.dtype("M8[s]"))),
],
)
assert ak.almost_equal(first, second)
4 changes: 2 additions & 2 deletions tests/test_2857_full_like_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def test():
arr = ak.Array([{"x": 1}, {"x": 2}])
# Fill with
result = ak.full_like(arr, np.datetime64(20, "s"), dtype="<M8[s]")
result = ak.full_like(arr, np.datetime64(20, "s"), dtype="M8[s]")
assert result.layout.is_equal_to(
ak.contents.RecordArray(
[
Expand All @@ -27,7 +27,7 @@ def test():
def test_typetracer():
arr = ak.Array([{"x": 1}, {"x": 2}], backend="typetracer")
# Fill with
result = ak.full_like(arr, np.datetime64(20, "s"), dtype="<M8[s]")
result = ak.full_like(arr, np.datetime64(20, "s"), dtype="M8[s]")
assert result.layout.form == (
ak.forms.RecordForm(
[ak.forms.NumpyForm("datetime64[s]")],
Expand Down
Loading