Skip to content

Commit

Permalink
fix: support empty record arrays in ak.to_numpy (#2012)
Browse files Browse the repository at this point in the history
* test: add test

* fix: fix `ak.to_numpy([{}])`
  • Loading branch information
agoose77 committed Dec 15, 2022
1 parent dfa96e4 commit 97d45fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/awkward/contents/recordarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def _to_numpy(self, allow_missing):
ValueError(f"cannot convert {self} into np.ndarray")
)
out = self._backend.nplike.empty(
contents[0].shape[0],
self.length,
dtype=[(str(n), x.dtype) for n, x in zip(self.fields, contents)],
)
mask = None
Expand Down
7 changes: 7 additions & 0 deletions tests/test_1944-to-numpy-empty-record-array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

import awkward as ak


def test():
assert ak.to_numpy(ak.Array([{}, {}])).tolist() == [(), ()]

0 comments on commit 97d45fe

Please sign in to comment.