Skip to content

BUG/API Should pd.NaT < "foo" raise? #35046

Closed
@jbrockmendel

Description

@jbrockmendel

If we treat NaT as a datetime, we would expect pd.NaT == "foo" to return False, != to return True, and for the inequalities to raise:

>>> np.datetime64("NaT", "ns") < "foo"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'numpy.ndarray' and 'str'

>>> np.nan < "foo"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'float' and 'str'

>>> pd.NaT < "foo"
False

It isn't obvious to me that the existing behavior is intentional. If we change this to raise, we can simplify NaT.__richcmp__ a bit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeError ReportingIncorrect or improved errors from pandasMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions