-
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.
* ak.ravel + testing * [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
06e1ca8
commit c471a04
Showing
3 changed files
with
137 additions
and
51 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,88 @@ | ||
# 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 | ||
|
||
content = ak._v2.contents.NumpyArray(np.array([0, 1, 2, 3, 4, 3, 6, 5, 2, 2])) | ||
|
||
|
||
def test_one_level(): | ||
layout = ak._v2.contents.ListOffsetArray( | ||
ak._v2.index.Index64(np.array([0, 3, 6, 6, 8, 10], dtype=np.int64)), content | ||
) | ||
|
||
# Test that all one level of nesting is removed | ||
assert to_list(ak._v2.operations.structure.ravel(layout)) == [ | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
3, | ||
6, | ||
5, | ||
2, | ||
2, | ||
] | ||
|
||
|
||
def test_two_levels(): | ||
inner = ak._v2.contents.ListOffsetArray( | ||
ak._v2.index.Index64(np.array([0, 3, 6, 6, 8, 10], dtype=np.int64)), content | ||
) | ||
layout = ak._v2.contents.ListOffsetArray( | ||
ak._v2.index.Index64(np.array([0, 2, 4, 5], dtype=np.int64)), inner | ||
) | ||
|
||
# Test that all one level of nesting is removed | ||
assert to_list(ak._v2.operations.structure.ravel(layout)) == [ | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
3, | ||
6, | ||
5, | ||
2, | ||
2, | ||
] | ||
|
||
|
||
def test_record(): | ||
x = ak._v2.contents.ListOffsetArray( | ||
ak._v2.index.Index64(np.array([0, 3, 5], dtype=np.int64)), content | ||
) | ||
y = ak._v2.contents.ListOffsetArray( | ||
ak._v2.index.Index64(np.array([5, 7, 10], dtype=np.int64)), content | ||
) | ||
layout = ak._v2.contents.RecordArray((x, y), ("x", "y")) | ||
assert to_list(ak._v2.operations.structure.ravel(layout)) == [ | ||
0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
3, | ||
6, | ||
5, | ||
2, | ||
2, | ||
] | ||
|
||
|
||
def test_option(): | ||
inner = ak._v2.contents.ListOffsetArray( | ||
ak._v2.index.Index64(np.array([0, 3, 6, 6, 8, 10], dtype=np.int64)), content | ||
) | ||
|
||
# Test that Nones are omitted | ||
layout = ak._v2.contents.IndexedOptionArray( | ||
ak._v2.index.Index64(np.array([0, -1, 2, -1, 4])), inner | ||
) | ||
assert to_list(ak._v2.operations.structure.ravel(layout)) == [0, 1, 2, 2, 2] |