-
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.
feat: add
.attrs
to highlevel objects (#2757)
* feat: add initial implementation of attrs * refactor: move pickling to private module * fix: implement support for disabling custom pickle in tests * test: test attrs * test: fix old test usage (unrelated) * test: importorskip arrow (unrelated) * test: raise TypeError for `to_regular` * feat: change prefix to `@` * test: update test * fix: use of `ctx.behavior` * refactor: store `attrs` on `NumbaLookup` * fix: more removals
- Loading branch information
Showing
163 changed files
with
3,260 additions
and
1,968 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
from __future__ import annotations | ||
|
||
from collections.abc import Mapping | ||
|
||
from awkward._typing import Any, JSONMapping | ||
|
||
|
||
def attrs_of_obj(obj, attrs: Mapping | None = None) -> Mapping | None: | ||
from awkward.highlevel import Array, ArrayBuilder, Record | ||
|
||
if attrs is not None: | ||
return attrs | ||
elif isinstance(obj, (Array, Record, ArrayBuilder)): | ||
return obj._attrs | ||
else: | ||
return None | ||
|
||
|
||
def attrs_of(*arrays, attrs: Mapping | None = None) -> Mapping: | ||
# An explicit 'attrs' always wins. | ||
if attrs is not None: | ||
return attrs | ||
|
||
copied = False | ||
for x in reversed(arrays): | ||
x_attrs = attrs_of_obj(x) | ||
if x_attrs is None: | ||
continue | ||
if attrs is None: | ||
attrs = x_attrs | ||
elif attrs is x_attrs: | ||
pass | ||
elif not copied: | ||
attrs = dict(attrs) | ||
attrs.update(x_attrs) | ||
copied = True | ||
else: | ||
attrs.update(x_attrs) | ||
return attrs | ||
|
||
|
||
def without_transient_attrs(attrs: dict[str, Any]) -> JSONMapping: | ||
return {k: v for k, v in attrs.items() if not k.startswith("@")} |
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
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
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
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
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
Oops, something went wrong.