Comparing Strings to Numbers: No ValueError · Issue #11565 · pandas-dev/pandas (original) (raw)
I noticed this quirk today: When you do a DataFrame-wide comparison (excluding ==
) using a number, it doesn't raise a ValueError (which you'd expect in Python 3); instead it always returns True.
from pandas import DataFrame df = DataFrame(x: {'x': 'foo', 'y': 'bar', 'z': 'baz'} for x in ['a', 'b', 'c']}) df a b c x foo foo foo y bar bar bar z baz baz baz df < 0 a b c x True True True y True True True z True True True df > 0 a b c x True True True y True True True z True True True
However, when you compare a Series of strings to a number, you get the expected ValueError:
df.a < 0 TypeError: unorderable types: str() < int()
Is this a bug or a feature?
Python: 3.4.3
Pandas: 0.17.0
OS: Mac OSX 10.11