Skip to content

BUG: Boolean indexing broken in np.flatiter #17175

@BvB93

Description

@BvB93

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 index

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions