Skip to content

Comparing Strings to Numbers: No ValueError #11565

Closed
@mattayes

Description

@mattayes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions