Skip to content

Commit

Permalink
fix: concatenation of empty records
Browse files Browse the repository at this point in the history
  • Loading branch information
pfackeldey committed Nov 22, 2024
1 parent 4db7973 commit 93f8ec7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/awkward/contents/recordarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,13 @@ def _mergemany(self, others: Sequence[Content]) -> Content:
):
minlength = merged.length

if minlength is unknown_length:
# `not for_each_field`: is a corner-case when all
# the arrays are empty and have no fields either.
if minlength is unknown_length or not for_each_field:
from operator import attrgetter

minlength = self.length
for x in others:
minlength += x.length
minlength += sum(map(attrgetter("length"), others))

next = RecordArray(
nextcontents,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_3258_concat_empty_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

import awkward as ak


def test_concat_empty_records():
a = ak.Array([{}, {}, {}])
b = ak.Array([{}, {}])
c = ak.concatenate([a, b], axis=0)
assert c.to_list() == [{}, {}, {}, {}, {}]

0 comments on commit 93f8ec7

Please sign in to comment.