Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sorting of record arrays without fields (ak.zip(tuple(...))) #3314

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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/contents/recordarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def _argsort_next(
raise NotImplementedError

def _sort_next(self, negaxis, starts, parents, outlength, ascending, stable):
if self._fields is None or len(self._fields) == 0:
if len(self.fields) == 0:
return ak.contents.NumpyArray(
self._backend.nplike.instance().empty(0, dtype=np.int64),
parameters=None,
Expand Down
23 changes: 23 additions & 0 deletions tests/test_1316_sort_recordarrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

import numpy as np

import awkward as ak


def test_sort_record():
a = ak.contents.NumpyArray(np.array([50, 500, 100, 1, 200, 1000]))

record = ak.Array(ak.contents.RecordArray([a, a[::-1]], ["a", "b"]))

assert ak.to_list(ak.sort(record)["a"]) == [1, 50, 100, 200, 500, 1000]
assert ak.to_list(ak.sort(record)["b"]) == [1, 50, 100, 200, 500, 1000]


def test_sort_record_tuple():
a = ak.contents.NumpyArray(np.array([50, 500, 100, 1, 200, 1000]))

record = ak.Array(ak.contents.RecordArray([a, a[::-1]], None))

assert ak.to_list(ak.sort(record)["0"]) == [1, 50, 100, 200, 500, 1000]
assert ak.to_list(ak.sort(record)["1"]) == [1, 50, 100, 200, 500, 1000]
Loading