pandas icon indicating copy to clipboard operation
pandas copied to clipboard

QST: pd.series indexing True auto 0 change

Open sc303030 opened this issue 3 years ago • 2 comments

Research

  • [X] I have searched the [pandas] tag on StackOverflow for similar questions.

  • [X] I have asked my usage related question on StackOverflow.

Link to question on StackOverflow

https://stackoverflow.com/questions/73783112/1-4-4-other-1-5-0-pd-series-indexing-true-auto-0-change

Question about pandas

test = pd.Series({True: 0, False: 0})

1.4.4
print(test[0])
> 0

but 
1.5.0
print(test[True])

> keyerror 0

1.4.4 and 1.5.0 What has changed?I can't find it

sc303030 avatar Sep 20 '22 07:09 sc303030

Hi, thanks for your report. test[True] works for me while test[0] does not. We are now supporting a boolean index, see #45061

@jbrockmendel I guess this is the correct behavior now?

phofl avatar Sep 20 '22 08:09 phofl

test.loc[1] should definitely raise, but it may be that test.index._should_fallback_to_positional should be True, in which case the __getitem__ call should still work (but would have different behavior on test[::-1])

jbrockmendel avatar Sep 20 '22 15:09 jbrockmendel