-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: propagate attrs & behavior with dict-like
ak.Array
input …
…data (#3374) * refactor: propagate attrs & behavior from given input arrays in the same way as ak.zip * add test
- Loading branch information
1 parent
6c01d57
commit f06dad9
Showing
2 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/test_3374_propagate_metadata_akArray_dictlike_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE | ||
# ruff: noqa: E402 | ||
|
||
from __future__ import annotations | ||
|
||
import awkward as ak | ||
|
||
|
||
def test_attrs(): | ||
x = ak.Array([1], attrs={"me": "ta"}) | ||
y = ak.Array([1], attrs={"da": "ta"}) | ||
|
||
rec = ak.Array({"x": x, "y": y}) | ||
assert rec.attrs == {"me": "ta", "da": "ta"} | ||
|
||
# overwrite attrs: | ||
rec = ak.Array({"x": x, "y": y}, attrs={"foo": "bar"}) | ||
assert rec.attrs == {"foo": "bar"} | ||
|
||
|
||
def test_behaviors(): | ||
behavior = {"foo": object()} | ||
x = ak.Array([1], behavior=behavior) | ||
y = ak.Array([1], behavior=behavior) | ||
|
||
rec = ak.Array({"x": x, "y": y}) | ||
assert rec.behavior == behavior | ||
|
||
# overwrite behavior: | ||
behavior2 = {"bar": object()} | ||
rec = ak.Array({"x": x, "y": y}, behavior=behavior2) | ||
assert rec.behavior == behavior2 |