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

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

Open
asmeurer opened this issue Nov 21, 2023 · 1 comment
Open

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

asmeurer opened this issue Nov 21, 2023 · 1 comment

Comments

@asmeurer
Copy link
Member

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):

asmeurer added a commit to asmeurer/ndindex that referenced this issue Nov 21, 2023
This is because of Quansight-Labs#167. When
we fix that issue, we should set this back to True.
@asmeurer
Copy link
Member Author

asmeurer commented Jan 3, 2024

Maybe we could raise them all together with an exception group. Not sure if it's a good idea, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant