Skip to content

REGR: RangeIndex __getitem__ filtering with boolean extension array of length 1 #63391

@jorisvandenbossche

Description

@jorisvandenbossche

This fails with main but works with released pandas:

>>> idx = pd.RangeIndex(1)
>>> idx[pd.Series([True])]
RangeIndex(start=0, stop=1, step=1)
>>> idx[pd.Series([True]).array]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[80], line 1
----> 1 idx[pd.Series([True]).array]

File ~/scipy/repos/pandas/pandas/core/indexes/range.py:1309, in RangeIndex.__getitem__(self, key)
   1307     key = np.flatnonzero(key)
   1308 try:
-> 1309     return self.take(key)
   1310 except (TypeError, ValueError):
   1311     return super().__getitem__(key)

File ~/scipy/repos/pandas/pandas/core/indexes/range.py:1508, in RangeIndex.take(self, indices, axis, allow_fill, fill_value, **kwargs)
   1506 ind_max = indices.max()
   1507 if ind_max >= len(self):
-> 1508     raise IndexError(
   1509         f"index {ind_max} is out of bounds for axis 0 with size {len(self)}"
   1510     )
   1511 ind_min = indices.min()
   1512 if ind_min < -len(self):

IndexError: index 1 is out of bounds for axis 0 with size 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexRelated to the Index class or subclassesIndexingRelated to indexing on series/frames, not to indexes themselvesRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions