-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
BUG: Boolean indexing broken in np.flatiter #17175
Copy link
Copy link
Open
Description
While attempting to address #17113 I stumbled upon an issue with flatiter and boolean indexing:
It appears that the latter only works as intended if a boolean array is passed.
If, for example, a list of booleans is passed instead then they're treated as normal integers.
As can be seen below, things get even more "creative" when dealing with plain booleans.
Note that the flatiter documentation does claim that advanced indexing is supported (docs).
Reproducing code example:
In [1]: import sys; import numpy as np
In [2]: sys.version
Out[2]: '3.8.3 | packaged by conda-forge | (default, Jun 1 2020, 17:21:09) \n[Clang 9.0.1 ]'
In [3]: np.__version__
Out[3]: '1.20.0.dev0+32b3f82'
In [4]: a: np.flatiter = np.arange(4).flat
# Behaves as expected
In [5]: a[np.array([True, True, True, True])]
Out[5]: array([0, 1, 2, 3])
# The booleans are treated as normal integers
In [6]: a[[True, True, True, True]]
Out[6]: array([1, 1, 1, 1])
# Not even sure what's going on at this point
In [7]: a[True]
Out[7]: 0
In [8]: a[False]
Out[8]: array([], dtype=int64)
In [9]: a[np.bool_(True)]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-31-b696e95f8475> in <module>
----> 1 a[np.bool_(True)]
IndexError: unsupported iterator indexReactions are currently unavailable