I have the following MCVE:
import pandas as pd
df = pd.DataFrame([True, False, True])
print(df[df == True])
if cond is True
Name: 0, dtype: bool
The catch here is that in
df[df == True], you are not comparing objects to
As the other answers say,
== is overloaded in
pandas to produce a
Series instead of a
bool as it normally does.
 is overloaded, too, to interpret the
Series and give the filtered result. The code is essentially equivalent to:
series = df.__eq__(True) df.__getitem__(series)
So, you're not violating PEP8 by leaving
pandas gives familiar syntax unusual semantics - that is what caused the confusion.
Accoring to Stroustroup (sec.3.3.3), operator overloading has been causing trouble due to this ever since its invention (and he had to think hard whether to include it into C++). Seeing even more abuse of it in C++, Gosling ran to the other extreme in Java, banning it completely, and that proved to be exactly that, an extreme.
As a conclusion, modern languages and code tend to have operator overloading but watch closely not to overuse it and for semantics to stay consistent.