Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: propagate attrs & behavior with dict-like ak.Array input data #3374

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/awkward/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,22 @@ def __init__(

elif isinstance(data, dict):
fields = []
contents = []
_arrays = []
length = None
for k, v in data.items():
fields.append(k)
contents.append(Array(v).layout)
_arrays.append(Array(v))
if length is None:
length = contents[-1].length
elif length != contents[-1].length:
length = _arrays[-1].layout.length
elif length != _arrays[-1].layout.length:
raise ValueError(
"dict of arrays in ak.Array constructor must have arrays "
f"of equal length ({length} vs {contents[-1].length})"
f"of equal length ({length} vs {_arrays[-1].layout.length}). "
"For automatic broadcasting use 'ak.zip' instead. "
)
layout = ak.contents.RecordArray(contents, fields)
layout = ak.contents.RecordArray([arr.layout for arr in _arrays], fields)
attrs = attrs_of(*_arrays, attrs=attrs)
ianna marked this conversation as resolved.
Show resolved Hide resolved
behavior = behavior_of(*_arrays, behavior=behavior)

elif isinstance(data, str):
layout = ak.operations.from_json(data, highlevel=False)
Expand Down
Loading