-
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.
C++ refactoring: ak.with_name (#1233)
* Worked on ak.with_name, two tests remaining to be fixed * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Renamed ak.with_name test to match the PR nr * Fixed issue on mergemany for recordarray parameters * Fixed all params passing in mergemany Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5738923
commit ab65e20
Showing
8 changed files
with
196 additions
and
56 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
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
34 changes: 34 additions & 0 deletions
34
tests/v2/test_0049-distinguish-record-and-recordarray-behaviors.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,34 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
from __future__ import absolute_import | ||
|
||
import pytest # noqa: F401 | ||
import numpy as np # noqa: F401 | ||
import awkward as ak # noqa: F401 | ||
|
||
|
||
class Point(ak._v2.record.Record): | ||
def __repr__(self): | ||
return "<{} {}>".format(self["x"], self["y"]) | ||
|
||
|
||
@pytest.mark.skip(reason="Missing check for overridden __repr__") | ||
def test(): | ||
behavior = {} | ||
behavior["__typestr__", "Point"] = "P" | ||
behavior["Point"] = Point | ||
array = ak._v2.highlevel.Array( | ||
[ | ||
[{"x": 1, "y": [1.1]}, {"x": 2, "y": [2.0, 0.2]}], | ||
[], | ||
[{"x": 3, "y": [3.0, 0.3, 3.3]}], | ||
], | ||
with_name="Point", | ||
behavior=behavior, | ||
check_valid=True, | ||
) | ||
assert repr(array[0, 0]) == "<1 [1.1]>" | ||
assert repr(array[0]) == "<Array [<1 [1.1]>, <2 [2, 0.2]>] type='2 * P'>" | ||
assert ( | ||
repr(array) == "<Array [[<1 [1.1]>, ... <3 [3, 0.3, 3.3]>]] type='3 * var * P'>" | ||
) |
29 changes: 29 additions & 0 deletions
29
tests/v2/test_0788-indexedarray-carrying-recordarray-parameters.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,29 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
from __future__ import absolute_import | ||
|
||
import pytest # noqa: F401 | ||
import numpy as np # noqa: F401 | ||
import awkward as ak # noqa: F401 | ||
|
||
|
||
def test(): | ||
one = ak._v2.highlevel.Array([[{"x": 1}], [], [{"x": 2}]], with_name="One") | ||
two = ak._v2.highlevel.Array([[{"x": 1.1}], [], [{"x": 2.2}]], with_name="Two") | ||
assert ( | ||
str( | ||
ak._v2.operations.structure.with_name( | ||
ak._v2.operations.structure.concatenate([one, two], axis=1), "All" | ||
).type | ||
) | ||
== "3 * var * All[x: float64]" | ||
) | ||
assert ( | ||
str( | ||
ak._v2.operations.structure.with_name( | ||
ak._v2.operations.structure.concatenate([one[1:], two[1:]], axis=1), | ||
"All", | ||
).type | ||
) | ||
== "2 * var * All[x: float64]" | ||
) |
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,79 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
from __future__ import absolute_import | ||
|
||
import pytest # noqa: F401 | ||
import numpy as np # noqa: F401 | ||
import awkward as ak # noqa: F401 | ||
|
||
to_list = ak._v2.operations.convert.to_list | ||
|
||
|
||
def test_with_name(): | ||
array = ak._v2.highlevel.Array( | ||
[ | ||
{"x": 0.0, "y": []}, | ||
{"x": 1.1, "y": [1]}, | ||
{"x": 2.2, "y": [2, 2]}, | ||
{"x": 3.3, "y": [3, 3, 3]}, | ||
] | ||
) | ||
|
||
one = ak._v2.operations.structure.with_name(array, "Wilbur") | ||
assert isinstance(one.layout, ak._v2.contents.Content) | ||
assert one.layout.parameters["__record__"] == "Wilbur" | ||
|
||
array2 = ak._v2.operations.convert.from_iter( | ||
[ | ||
[[1], 2.2, [2, 2], 3.3, [3, 3, 3], 4.4, [4, 4, 4, 4]], | ||
[ | ||
{"x": 0.0, "y": []}, | ||
{"x": 1.1, "y": [1]}, | ||
{"x": 2.2, "y": [2, 2]}, | ||
{"x": 3.3, "y": [3, 3, 3]}, | ||
], | ||
], | ||
highlevel=False, | ||
) | ||
one = ak._v2.operations.structure.with_name(array2, "Wilbur") | ||
assert one.layout.content.contents[2].parameters["__record__"] == "Wilbur" | ||
|
||
array = ak._v2.highlevel.Array( | ||
[ | ||
{"a": [[0.0, 4.5], [], None], "b": []}, | ||
{"a": 1.1, "b": [[1]]}, | ||
] | ||
) | ||
one = ak._v2.operations.structure.with_name(array, "James") | ||
assert isinstance(one.layout, ak._v2.contents.Content) | ||
assert one.layout.parameters["__record__"] == "James" | ||
|
||
|
||
def test_simplify_unionarray_with_name(): | ||
one = ak._v2.operations.convert.from_iter([5, 4, 3, 2, 1], highlevel=False) | ||
two = ak._v2.operations.convert.from_iter( | ||
[[], [1], [2, 2], [3, 3, 3]], highlevel=False | ||
) | ||
three = ak._v2.operations.convert.from_iter( | ||
[ | ||
{"x": 0.0, "y": []}, | ||
{"x": 1.1, "y": [1]}, | ||
{"x": 2.2, "y": [2, 2]}, | ||
{"x": 3.3, "y": [3, 3, 3]}, | ||
], | ||
highlevel=False, | ||
) | ||
|
||
tags2 = ak._v2.index.Index8(np.array([0, 1, 0, 1, 0, 0, 1], dtype=np.int8)) | ||
index2 = ak._v2.index.Index32(np.array([0, 0, 1, 1, 2, 3, 2], dtype=np.int32)) | ||
inner = ak._v2.contents.UnionArray(tags2, index2, [two, three]) | ||
tags1 = ak._v2.index.Index8( | ||
np.array([0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0], dtype=np.int8) | ||
) | ||
index1 = ak._v2.index.Index64( | ||
np.array([0, 1, 0, 1, 2, 2, 3, 4, 5, 3, 6, 4], dtype=np.int64) | ||
) | ||
outer = ak._v2.contents.UnionArray(tags1, index1, [one, inner]) | ||
one = ak._v2.operations.structure.with_name(outer, "James") | ||
|
||
assert outer.contents[1].is_UnionType != one.layout.contents[1].is_UnionType |