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

ak.unflatten on a nested IndexedOptionArray typetracer hits a bug trying to calculate lengths #2910

Closed
lgray opened this issue Dec 21, 2023 · 1 comment · Fixed by #2912
Closed
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged

Comments

@lgray
Copy link
Contributor

lgray commented Dec 21, 2023

Version of Awkward Array

2.5.1

Description and code to reproduce

import json
import awkward as ak

fromjson = {
    "class": "ListOffsetArray",
    "offsets": "i64",
    "content": {
        "class": "ListOffsetArray",
        "offsets": "i64",
        "content": {
            "class": "IndexedOptionArray",
            "index": "i64",
            "content": {
                "class": "RecordArray",
                "fields": [
                    "pt",
                ],
                "contents": [
                    {
                        "class": "NumpyArray",
                        "primitive": "float32",
                        "inner_shape": [],
                        "parameters": {"__doc__": "pt"},
                        "form_key": None,
                    },
                ],
                "parameters": {
                    "__record__": "PFCand",
                    "__doc__": "interesting particles from various jet collections",
                    "collection_name": "PFCands",
                },
                "form_key": None,
            },
            "parameters": {},
            "form_key": None,
        },
        "parameters": {},
        "form_key": None,
    },
    "parameters": {},
    "form_key": None,
}

form = ak.forms.from_json(json.dumps(fromjson))

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

ttarray = ak.Array(ttlayout, behavior=ak.behavior)

flattened = ak.flatten(ttarray, axis=2)

counts = ak.flatten(ak.num(ttarray, axis=2), axis=1)

unflattened = ak.unflatten(flattened, counts, axis=1)

Yields the following error:

Traceback (most recent call last):
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/_dispatch.py", line 62, in dispatch
    next(gen_or_result)
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/operations/ak_unflatten.py", line 90, in unflatten
    return _impl(array, counts, axis, highlevel, behavior, attrs)
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/operations/ak_unflatten.py", line 98, in _impl
    ctx.unwrap(array, allow_record=False, primitive_policy="error").to_packed(),
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/contents/listoffsetarray.py", line 2219, in to_packed
    next_content = next._content[: next._offsets[-1]].to_packed()
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/contents/indexedoptionarray.py", line 1725, in to_packed
    len(original_index) - num_none
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/_nplikes/typetracer.py", line 320, in __len__
    raise AssertionError(
AssertionError: bug in Awkward Array: attempt to get length of a TypeTracerArray

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "form_madness16.py", line 54, in <module>
    unflattened = ak.unflatten(flattened, counts, axis=1)
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/_dispatch.py", line 70, in dispatch
    return gen_or_result
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/_errors.py", line 85, in __exit__
    self.handle_exception(exception_type, exception_value)
  File "/Users/lgray/miniforge3/envs/coffea-dev/lib/python3.8/site-packages/awkward/_errors.py", line 95, in handle_exception
    raise self.decorate_exception(cls, exception)
AssertionError: bug in Awkward Array: attempt to get length of a TypeTracerArray

See if this has been reported at https://github.com/scikit-hep/awkward/issues
@lgray lgray added the bug (unverified) The problem described would be a bug, but needs to be triaged label Dec 21, 2023
@lgray
Copy link
Contributor Author

lgray commented Dec 21, 2023

@cmoore24-24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant