diff --git a/src/awkward/contents/recordarray.py b/src/awkward/contents/recordarray.py index 4aafcfd6b2..761e30b7d1 100644 --- a/src/awkward/contents/recordarray.py +++ b/src/awkward/contents/recordarray.py @@ -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, diff --git a/tests/test_3258_concat_empty_records.py b/tests/test_3258_concat_empty_records.py new file mode 100644 index 0000000000..e6b37967fb --- /dev/null +++ b/tests/test_3258_concat_empty_records.py @@ -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() == [{}, {}, {}, {}, {}]