-
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.
fix: handle unhashable behaviour type (#2770)
* fix: handle unhashable behaviour type * fix: add checks for None * fix: use arrayview functions - Jim's suggestion * fix: cleanup * test: add a test for a non-pickleable behaviour * test: rename the test * fix: clenup * test: compare behaviours * test: add more checks * test: just check keys --------- Co-authored-by: Angus Hollands <[email protected]>
- Loading branch information
Showing
4 changed files
with
66 additions
and
3 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
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
43 changes: 43 additions & 0 deletions
43
tests/test_2770_serialize_and_deserialize_behaviour_for_numba.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,43 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import awkward as ak | ||
|
||
numba = pytest.importorskip("numba") | ||
|
||
|
||
@numba.njit | ||
def func(array): | ||
return array | ||
|
||
|
||
def test_ArrayBuilder_behavior(): | ||
SOME_ATTRS = {"FOO": "BAR"} | ||
builder = ak.ArrayBuilder(behavior=SOME_ATTRS) | ||
|
||
assert builder.behavior is SOME_ATTRS | ||
assert func(builder).behavior == SOME_ATTRS | ||
|
||
|
||
def test_ArrayBuilder_non_picklable_behavior(): | ||
def make_add_xyr(): | ||
def add_xyr(left, right): | ||
x = left.x + right.x | ||
y = left.y + right.y | ||
return ak.zip( | ||
{ | ||
"x": x, | ||
"y": y, | ||
"r": np.sqrt(x**2 + y**2), | ||
}, | ||
with_name="xyr", | ||
) | ||
|
||
return add_xyr | ||
|
||
behavior = {(np.add, "xyr", "xyr"): make_add_xyr()} | ||
builder = ak.ArrayBuilder(behavior=behavior) | ||
result = func(builder) | ||
assert result.behavior.keys() == behavior.keys() |