Skip to content

API: Index.__getitem__(True) returns 2D ndarray #44051

Closed
@jbrockmendel

Description

@jbrockmendel

  • 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 master branch of pandas.

Reproducible Example

Not clear if this is intentional:


import numpy as np
import pandas as pd

arr = np.random.randn(4)
idx = pd.Index(arr)

idx[True]

>>> idx[True]
array([[ 1.39365849, -0.03655461,  0.17112114, -1.4612337 ]])

Issue Description

For other cases where indexing on index._data returns 2D (e.g. idx[:, None]) we issue a FutureWarning, but this goes through a different code path.

Expected Behavior

I don't have an opinion here, just think whatever we do should be intentional

Installed Versions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions