Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle type tracer correctly in indexed option array flattening #3325

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/awkward/contents/indexedoptionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content]

offsets, flattened = next._offsets_and_flattened(axis, depth)

if offsets.length == 0:
if offsets.length is not unknown_length and offsets.length == 0:
return (
offsets,
ak.contents.IndexedOptionArray(
Expand Down
54 changes: 54 additions & 0 deletions tests/test_3325_ak_flatten_indexed_option_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import annotations

import pytest

import awkward as ak

fromdict = {
"class": "ListOffsetArray",
"offsets": "i64",
"content": {
"class": "ListOffsetArray",
"offsets": "i64",
"content": {
"class": "IndexedOptionArray",
"index": "i64",
"content": {
"class": "ListOffsetArray",
"offsets": "i64",
"content": {
"class": "IndexedOptionArray",
"index": "i64",
"content": {
"class": "NumpyArray",
"primitive": "float32",
"inner_shape": [],
"parameters": {},
"form_key": None,
},
"parameters": {},
"form_key": None,
},
"parameters": {},
"form_key": None,
},
"parameters": {},
"form_key": None,
},
"parameters": {},
"form_key": None,
},
"parameters": {},
"form_key": None,
}

form = ak.forms.from_dict(fromdict)

ttlayout, report = ak.typetracer.typetracer_with_report(form)

ttarray = ak.Array(ttlayout)


@pytest.mark.parametrize("ax", [None, 0, 1, 2, 3])
def test_3325_flatten_index_option_array(ax):
ak.flatten(ttarray, axis=ax)
Loading