Skip to content

Commit 28a89da

Browse files
authored
fix: prevent exponential memory growth in UnionArray (#3119)
1 parent 6cff8e9 commit 28a89da

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/awkward/contents/unionarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def simplified(
431431
]
432432

433433
if len(contents) == 1:
434-
next = contents[0]._carry(index, True)
434+
next = contents[0]._carry(index, False)
435435
return next.copy(parameters=parameters_union(next._parameters, parameters))
436436

437437
else:
@@ -702,7 +702,7 @@ def project(self, index):
702702
nextcarry = ak.index.Index64(
703703
tmpcarry.data[: lenout[0]], nplike=self._backend.index_nplike
704704
)
705-
return self._contents[index]._carry(nextcarry, True)
705+
return self._contents[index]._carry(nextcarry, False)
706706

707707
@staticmethod
708708
def regular_index(

tests/test_2713_from_buffers_allow_noncanonical.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ def test_union_simplification():
120120
projected = ak.from_buffers(
121121
projected_form, length, container, allow_noncanonical_form=True
122122
)
123+
123124
assert projected.layout.form.to_dict(verbose=False) == {
124-
"class": "IndexedArray",
125-
"index": "i64",
126-
"content": {"class": "RecordArray", "fields": ["x"], "contents": ["int64"]},
125+
"class": "RecordArray",
126+
"fields": ["x"],
127+
"contents": ["int64"],
127128
}
128129
assert ak.almost_equal(array[["x"]], projected)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
2+
3+
from __future__ import annotations
4+
5+
import awkward as ak
6+
7+
8+
def test():
9+
one_a = ak.Array([{"x": 1, "y": 2}], with_name="T")
10+
one_b = ak.Array([{"x": 1, "y": 2}], with_name="T")
11+
two_a = ak.Array([{"x": 1, "z": 3}], with_name="T")
12+
two_b = ak.Array([{"x": 1, "z": 3}], with_name="T")
13+
three = ak.Array([{"x": 4}, {"x": 4}], with_name="T")
14+
15+
first = ak.zip({"a": one_a, "b": one_b})
16+
second = ak.zip({"a": two_a, "b": two_b})
17+
18+
cat = ak.concatenate([first, second], axis=0)
19+
20+
cat["another"] = three
21+
22+
def check(layout):
23+
if hasattr(layout, "contents"):
24+
for x in layout.contents:
25+
check(x)
26+
elif hasattr(layout, "content"):
27+
check(layout.content)
28+
else:
29+
assert layout.length <= 2
30+
31+
for _ in range(5):
32+
check(cat.layout)
33+
34+
cat["another", "w"] = three.x

0 commit comments

Comments
 (0)