Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
jbrockmendel opened this issue Oct 16, 2021 · 1 comment · Fixed by #44973
Closed
3 tasks done

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

jbrockmendel opened this issue Oct 16, 2021 · 1 comment · Fixed by #44973
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Oct 16, 2021

  • 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()

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 16, 2021
@mroeschke mroeschke added Indexing Related to indexing on series/frames, not to indexes themselves and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 16, 2021
@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Oct 20, 2021

To be explicit for other readers, this is following the numpy behaviour:

In [2]: arr = np.array([1, 2, 3])

In [3]: arr[True]
Out[3]: array([[1, 2, 3]])

(I don't fully understand the rationale of the numpy behaviour here, though ..)

Personally I think we should be consistent with the other cases that currently returns a 2D array -> deprecate this and disallow it in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants