-
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: do not increment field index for nested lists (#1303)
* Fix: do not increment field index for nested lists * Test: check that fix works! * Refactor: use simpler form keys * Test: check case for multiple lists * Test: make test more complex * Fix: correctly reset index when wrapping * Revert "Fix: correctly reset index when wrapping" This reverts commit b27e480. * Fix: correctly wrap index
- Loading branch information
Showing
2 changed files
with
98 additions
and
2 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,89 @@ | ||
# 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 | ||
|
||
|
||
def test(): | ||
builder = ak.layout.LayoutBuilder64( | ||
""" | ||
{ | ||
"form_key": "root", | ||
"class": "RecordArray", | ||
"contents": { | ||
"u": { | ||
"form_key": "u", | ||
"class": "ListOffsetArray64", | ||
"offsets": "i64", | ||
"content": { | ||
"form_key": "u-content", | ||
"class": "RecordArray", | ||
"contents": { | ||
"i": { | ||
"class": "NumpyArray", | ||
"primitive": "int64", | ||
"form_key": "i" | ||
}, | ||
"j": { | ||
"class": "ListOffsetArray64", | ||
"offsets": "i64", | ||
"content": "int64", | ||
"form_key": "j" | ||
} | ||
} | ||
} | ||
}, | ||
"v": { | ||
"class": "NumpyArray", | ||
"primitive": "int64", | ||
"form_key": "v" | ||
}, | ||
"w": { | ||
"class": "NumpyArray", | ||
"primitive": "int64", | ||
"form_key": "w" | ||
}, | ||
"x": { | ||
"class": "NumpyArray", | ||
"primitive": "int64", | ||
"form_key": "x" | ||
} | ||
} | ||
} | ||
""" | ||
) | ||
|
||
builder.begin_list() # u | ||
|
||
builder.int64(1) # i | ||
builder.begin_list() # j | ||
builder.int64(9) | ||
builder.int64(8) | ||
builder.int64(7) | ||
builder.end_list() # j | ||
|
||
builder.end_list() # u | ||
|
||
builder.int64(2) # v | ||
builder.int64(3) # w | ||
builder.int64(4) # x | ||
|
||
builder.begin_list() # u | ||
|
||
builder.int64(1) # i | ||
builder.begin_list() # j | ||
builder.int64(9) | ||
builder.int64(8) | ||
builder.int64(7) | ||
builder.end_list() # j | ||
|
||
builder.end_list() # u | ||
|
||
builder.int64(2) # v | ||
builder.int64(3) # w | ||
builder.int64(4) # x | ||
|
||
assert ak.to_list(builder.snapshot()) == [ | ||
{"u": [{"i": 1, "j": [9, 8, 7]}], "v": 2, "w": 3, "x": 4}, | ||
{"u": [{"i": 1, "j": [9, 8, 7]}], "v": 2, "w": 3, "x": 4}, | ||
] |