Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Biggus allows indexes which aren't allowed by numpy #187

Open
djkirkham opened this issue Aug 11, 2016 · 2 comments
Open

Biggus allows indexes which aren't allowed by numpy #187

djkirkham opened this issue Aug 11, 2016 · 2 comments

Comments

@djkirkham
Copy link
Contributor

djkirkham commented Aug 11, 2016

>>> import biggus
>>> import numpy as np
>>> a = np.arange(5)
>>> b = biggus.NumpyArrayAdapter(a)
>>> c = b[((1,),)]
>>> c.ndarray()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../biggus/_init.py", line 1455, in ndarray
    array = self._apply_keys()
  File ".../biggus/_init.py", line 1525, in _apply_keys
    array = self.concrete.__getitem__(keys)
IndexError: unsupported iterator index

This is the root of a hard-to-track-down bug in Iris, so it would be useful if an error was returned when the array was first indexed.

@djkirkham
Copy link
Contributor Author

djkirkham commented Aug 11, 2016

Interestingly, for a numpy array, the following access is fine:

a[[[1]]]

but not for a biggus NumpyArrayAdapter:

>>> b[[[1]]]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../biggus/_init.py", line 516, in __getitem__
    indexed_array = self._getitem_full_keys(keys)
  File ".../biggus/_init.py", line 1444, in _getitem_full_keys
    result_key = self._cleanup_new_key(new_key, size, axis)
  File ".../biggus/_init.py", line 1358, in _cleanup_new_key
    raise IndexError(msg)
IndexError: index [1] is out of bounds for axis 0 with size 5

And the following is fine for numpy:

a[[1]]

and biggus only fails at the call to b.ndarray:

>>> b[[1]]
<NumpyArrayAdapter shape=(1) dtype=dtype('int64')>
>>> b[[1]].ndarray()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../biggus/_init.py", line 1455, in ndarray
    array = self._apply_keys()
  File ".../biggus/_init.py", line 1525, in _apply_keys
    array = self.concrete.__getitem__(keys)
IndexError: unsupported iterator index

@djkirkham
Copy link
Contributor Author

djkirkham commented Aug 19, 2016

The initial issue is due to a numpy bug which is fixed in the latest version. Of the other two cases, the second (a[[1]]) is due to the same bug, while the first (a[[[1]]]) appears to be due to the fact that biggus expects arguments to __getitem__ to only be nested at most twice (e.g. 1, (1,) and ((1,),) are fine but (((1,),),) isn't), whereas numpy allows indefinite nesting

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant