Skip to content

BUG: Comparisons with non-comparable objects in DataFrame return True #4537

Closed
@jtratner

Description

@jtratner

I can't tell if this is expected or not (taken from part of test_where_datetime in tests/test_frame). The change in #3311 (which the test case came from) didn't specify what should happen with non-datetime comparisons. Right now they return True, which doesn't really make sense. They should probably return False instead.

In [16]: df = DataFrame(dict(A = date_range('20130102',periods=5),
                            B = date_range('20130104',periods=5),
                            C = np.random.randn(5)))

In [17]: stamp = datetime(2013,1,3)

In [18]: df
Out[18]:
                    A                   B         C
0 2013-01-02 00:00:00 2013-01-04 00:00:00 -0.321163
1 2013-01-03 00:00:00 2013-01-05 00:00:00  1.219840
2 2013-01-04 00:00:00 2013-01-06 00:00:00 -1.048629
3 2013-01-05 00:00:00 2013-01-07 00:00:00 -0.861459
4 2013-01-06 00:00:00 2013-01-08 00:00:00  1.480088

In [19]: df > stamp
Out[19]:
       A     B     C
0  False  True  True
1  False  True  True
2   True  True  True
3   True  True  True
4   True  True  True

In [20]: df < stamp
Out[20]:
       A      B     C
0   True  False  True
1  False  False  True
2  False  False  True
3  False  False  True
4  False  False  True

In [21]: df == stamp
Out[21]:
       A      B      C
0  False  False  False
1   True  False  False
2  False  False  False
3  False  False  False
4  False  False  False

In [22]: df != stamp
Out[22]:
       A     B     C
0   True  True  True
1  False  True  True
2   True  True  True
3   True  True  True
4   True  True  True

In [23: pd.__version__
Out[23]: '0.12.0-154-g7fd6b20'

Column C probably should be False for every case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions