1.4.4 other 1.5.0 pd.series indexing True auto 0 change

Viewed 23
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

1 Answers

test[0] is inherently unclear, and it looks like the updated version of pandas refuses to guess from your ambiguity.

By doing test[0] on a Series with a bool type index, you could mean:

  • test.iloc[0], which is silly, but you should do this explicitly if it's your intention.
  • test[False] ... remember 0 == False is True.
    • In this case, you should explicitly update code to be clear... test[bool(0)]

The keyerror is correct though, there is no 0 in Index([True, False], dtype='bool')

Related