Skip to content

ak.flatten raises np.AxisError for unknown[unknown], but not for unknown #2377

@HenryDayHall

Description

@HenryDayHall

Version of Awkward Array

2.1.1

Description and code to reproduce

To reproduce the problem;

[ins] In [1]: import awkward as ak
         ...: ak.__version__
Out[1]: '2.1.1'

[ins] In [3]: empty = ak.Array([])
         ...: ak.flatten(empty[empty])
---------------------------------------------------------------------------
AxisError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 ak.flatten(empty[empty])

File ~/Programs/anaconda3/envs/tree2/lib/python3.11/site-packages/awkward/operations/ak_flatten.py:164, in flatten(array, axis, highlevel, behavior)
     12 """
     13 Args:
     14     array: Array-like data (anything #ak.to_layout recognizes).
   (...)
    158      999]
    159 """
    160 with ak._errors.OperationErrorContext(
    161     "ak.flatten",
    162     {"array": array, "axis": axis, "highlevel": highlevel, "behavior": behavior},
    163 ):
--> 164     return _impl(array, axis, highlevel, behavior)

File ~/Programs/anaconda3/envs/tree2/lib/python3.11/site-packages/awkward/operations/ak_flatten.py:232, in _impl(array, axis, highlevel, behavior)
    229     return wrap_layout(out, behavior, highlevel, like=array)
    231 else:
--> 232     out = ak._do.flatten(layout, axis)
    233     return wrap_layout(out, behavior, highlevel, like=array)

File ~/Programs/anaconda3/envs/tree2/lib/python3.11/site-packages/awkward/_do.py:253, in flatten(layout, axis)
    252 def flatten(layout: Content, axis: int = 1) -> Content:
--> 253     offsets, flattened = layout._offsets_and_flattened(axis, 1)
    254     return flattened

File ~/Programs/anaconda3/envs/tree2/lib/python3.11/site-packages/awkward/contents/numpyarray.py:415, in NumpyArray._offsets_and_flattened(self, axis, depth)
    412     return self.to_RegularArray()._offsets_and_flattened(axis, depth)
    414 else:
--> 415     raise ak._errors.wrap_error(
    416         np.AxisError(f"axis={axis} exceeds the depth of this array ({depth})")
    417     )

AxisError: while calling

    ak.flatten(
        array = <Array [] type='0 * int64'>
        axis = 1
        highlevel = True
        behavior = None
    )

Error details: axis=1 exceeds the depth of this array (1)

where as by contrast, in the older versions;

[ins] In [1]: import awkward as ak
         ...: print(ak.__version__)
1.8.0

[nav] In [2]: empty = ak.Array([])
         ...: ak.flatten(empty[empty])
Out[2]: <Array [] type='0 * unknown'>

This does seem like a bug to me, we can't guarantee that every list that we call flatten on will have items in.

Not impossible that it's related to this bug; #2207
I will check out the repo some time and see if that fix solves it.

Metadata

Metadata

Assignees

Labels

bugThe problem described is something that must be fixed

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions