Skip to content

Commit

Permalink
fix: handle type tracer correctly in indexed option array flattening (#…
Browse files Browse the repository at this point in the history
…3325)

* fix: handle type tracer correctly in indexed option array

* add test

* lint

* lint

* lint

---------

Co-authored-by: Jim Pivarski <[email protected]>
  • Loading branch information
lgray and jpivarski authored Dec 5, 2024
1 parent 7d97988 commit 7191ce8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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)

0 comments on commit 7191ce8

Please sign in to comment.