Skip to content

Tuple.reduce with ellipses raises on the last invalid index #167

@asmeurer

Description

@asmeurer

For example:

>>> Tuple(..., 0, 0).reduce((0, 0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/aaronmeurer/Documents/ndindex/ndindex/tuple.py", line 367, in reduce
    s = s.reduce(shape, axis=axis, negative_int=negative_int)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aaronmeurer/Documents/ndindex/ndindex/integer.py", line 100, in reduce
    self._raise_indexerror(shape, axis)
  File "/Users/aaronmeurer/Documents/ndindex/ndindex/integer.py", line 63, in _raise_indexerror
    raise IndexError(f"index {self.raw} is out of bounds for axis {axis} with size {size}")
IndexError: index 0 is out of bounds for axis 1 with size 0

vs.

>>> np.empty((0, 0))[..., 0, 0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: index 0 is out of bounds for axis 0 with size 0

This means we have to set same_exception=False all over the tests.

It's because of the reverse loop

for i, s in enumerate(reversed(args[:ellipsis_i]), start=1):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions