Skip to content

BUG: inconsistency in Index.__getitem__ for Numpy and non-numpy dtypes #55820

Closed
@phofl

Description

@phofl

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

ser = pd.Index([1, 2], dtype="Int64")
ser[np.array([], dtype=np.bool_)]

This raises while NumPy dtypes, e.g. "int64" works.

Traceback (most recent call last):
  File "/Users/patrick/Library/Application Support/JetBrains/PyCharm2023.2/scratches/scratch.py", line 477, in <module>
    ser[np.array([], dtype=np.bool_)]
  File "/Users/patrick/PycharmProjects/pandas/pandas/core/indexes/base.py", line 5360, in __getitem__
    result = getitem(key)
  File "/Users/patrick/PycharmProjects/pandas/pandas/core/arrays/masked.py", line 182, in __getitem__
    item = check_array_indexer(self, item)
  File "/Users/patrick/PycharmProjects/pandas/pandas/core/indexers/utils.py", line 539, in check_array_indexer
    raise IndexError(
IndexError: Boolean index has wrong length: 0 instead of 2

Issue Description

Not sure what we want to expect here, the Series case raises for all dtypes

cc @jbrockmendel

Expected Behavior

See above

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorBugDeprecateFunctionality to remove in pandasIndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions