-
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: ak._v2.is_none check for axis value (#1539)
* Added an axis value check in * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Renamed tests with PR nr and fixes pre-commit issues * Fixed ak.is_none * Fixed axis value and added more tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
818b373
commit 8c070be
Showing
5 changed files
with
129 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
import pytest # noqa: F401 | ||
import numpy as np # noqa: F401 | ||
import awkward as ak # noqa: F401 | ||
|
||
|
||
def test(): | ||
assert ak._v2.operations.is_none(ak._v2.Array([1, 2, 3, None, 5])).tolist() == [ | ||
False, | ||
False, | ||
False, | ||
True, | ||
False, | ||
] | ||
assert ak._v2.operations.is_none( | ||
ak._v2.Array([[1, 2, 3], [], [None, 5]]) | ||
).tolist() == [ | ||
False, | ||
False, | ||
False, | ||
] | ||
assert ak._v2.operations.is_none( | ||
ak._v2.Array([[1, 2, 3], [], [None, 5]]), axis=1 | ||
).tolist() == [ | ||
[False, False, False], | ||
[], | ||
[True, False], | ||
] | ||
assert ak._v2.operations.is_none( | ||
ak._v2.Array([[1, None, 2, 3], [], [None, 5]]), axis=1 | ||
).tolist() == [ | ||
[False, True, False, False], | ||
[], | ||
[True, False], | ||
] | ||
assert ak._v2.operations.is_none( | ||
ak._v2.Array([[1, None, 2, 3], [], [None, 5]]), axis=-1 | ||
).tolist() == [ | ||
[False, True, False, False], | ||
[], | ||
[True, False], | ||
] | ||
assert ak._v2.operations.is_none( | ||
ak._v2.Array([[1, None, 2, 3], [], [None, 5]]), axis=-2 | ||
).tolist() == [ | ||
False, | ||
False, | ||
False, | ||
] | ||
assert ak._v2.operations.is_none( | ||
ak._v2.Array([[1, None, 2, 3], None, [None, 5]]), axis=-2 | ||
).tolist() == [False, True, False] | ||
with pytest.raises(ValueError): | ||
ak._v2.operations.is_none( | ||
ak._v2.Array([[1, None, 2, 3], [], [None, 5]]), axis=-3 | ||
) | ||
|
||
one = ak._v2.operations.from_iter([1, None, 3], highlevel=False) | ||
two = ak._v2.operations.from_iter([[], [1], None, [3, 3, 3]], highlevel=False) | ||
tags = ak._v2.index.Index8(np.array([0, 1, 1, 0, 0, 1, 1], dtype=np.int8)) | ||
index = ak._v2.index.Index64(np.array([0, 0, 1, 1, 2, 2, 3], dtype=np.int64)) | ||
array = ak._v2.Array( | ||
ak._v2.contents.UnionArray(tags, index, [one, two]), check_valid=True | ||
) | ||
assert ak._v2.to_list(array) == [1, [], [1], None, 3, None, [3, 3, 3]] | ||
|
||
assert ak._v2.to_list(ak._v2.operations.is_none(array)) == [ | ||
False, | ||
False, | ||
False, | ||
True, | ||
False, | ||
True, | ||
False, | ||
] |
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,20 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
import pytest # noqa: F401 | ||
import numpy as np # noqa: F401 | ||
import awkward as ak # noqa: F401 | ||
|
||
|
||
def test_numpy_array(): | ||
x = np.arange(12) | ||
y = ak._v2.operations.is_none(x) | ||
|
||
assert y.tolist() == [False] * 12 | ||
|
||
|
||
def test_awkward_from_numpy_array(): | ||
x = np.arange(12) | ||
y = ak._v2.operations.from_numpy(x) | ||
z = ak._v2.operations.is_none(y) | ||
|
||
assert z.tolist() == [False] * 12 |
File renamed without changes.
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,26 @@ | ||
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE | ||
|
||
import pytest # noqa: F401 | ||
import awkward as ak # noqa: F401 | ||
|
||
to_list = ak._v2.operations.to_list | ||
|
||
|
||
def test_1417issue_is_none_check_axis(): | ||
array = ak._v2.Array([[[1, 2, None], None], None]) | ||
|
||
assert to_list(ak._v2.is_none(array, axis=0)) == [False, True] | ||
assert to_list(ak._v2.is_none(array, axis=1)) == [[False, True], None] | ||
assert to_list(ak._v2.is_none(array, axis=2)) == [ | ||
[[False, False, True], None], | ||
None, | ||
] | ||
|
||
with pytest.raises(ValueError): | ||
ak._v2.is_none(array, axis=3) | ||
|
||
assert str(ak._v2.type(ak._v2.is_none(array, axis=0)[0])) == "bool" | ||
|
||
array = ak._v2.Array([[[[[1], [3]], [1]]], []]) | ||
|
||
assert to_list(ak._v2.is_none(array, axis=2)) == [[[False, False]], []] |