Skip to content

BUG: comparison of pandas NaT with datetime.date evaluating to True #39151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arc12 opened this issue Jan 13, 2021 · 6 comments · Fixed by #39196
Closed

BUG: comparison of pandas NaT with datetime.date evaluating to True #39151

arc12 opened this issue Jan 13, 2021 · 6 comments · Fixed by #39196
Labels
Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@arc12
Copy link

arc12 commented Jan 13, 2021

Code Sample, a copy-pastable example

import pandas
import datetime
pandas.NaT < datetime.datetime.now().date()

Problem description

I understood the convention is for NA-types to evaluate to False in all inequalities. The above code evaluates to True.

These DO evaluate to False, as expected.
pandas.NaT < datetime.datetime.now()
pandas.NaT > datetime.datetime.now().date()

This seems to have been introduced with 1.2.0, and to not have been the behaviour under 1.1.5.

Output of pd.show_versions()

commit           : 3e89b4c4b1580aa890023fc550774e63d499da25
python           : 3.7.9.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.18362
machine          : AMD64
processor        : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : None.None
pandas           : 1.2.0
numpy            : 1.19.2
pytz             : 2020.5
dateutil         : 2.8.1
pip              : 20.3.3
setuptools       : 51.1.2.post20210112
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : 1.3.7
lxml.etree       : 4.6.2
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.11.2
IPython          : 7.19.0
pandas_datareader: None
bs4              : None
bottleneck       : 1.3.2
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.3.2
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : 1.5.2
sqlalchemy       : 1.3.22
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : 0.52.0
@arc12 arc12 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 13, 2021
@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version Datetime Datetime data dtype and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 14, 2021
@jorisvandenbossche jorisvandenbossche added this to the 1.2.1 milestone Jan 14, 2021
@jorisvandenbossche
Copy link
Member

@arc12 Thanks for the report! I can confirm the regression.

cc @jbrockmendel

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Jan 14, 2021
@simonjayhawkins
Copy link
Member

simonjayhawkins commented Jan 14, 2021

This seems to have been introduced with 1.2.0, and to not have been the behaviour under 1.1.5.

first bad commit: [d82e540] BUG: NaT.cmp(invalid) should raise TypeError (#35585)

@jbrockmendel
Copy link
Member

Yah something similar came up for Timestamp. The solution is going to be to add in NaT.__richcmp__ something to the effect of

if PyDate_Check(other):
    if op == Py_EQ:
        return False
    if op == Py_NE:
        return True
     warn_that_this_is_deprecated_like_in_timestamp
     return False

@simonjayhawkins
Copy link
Member

@jbrockmendel do you have time to fix this before Monday? otherwise I can look into it.

@jbrockmendel
Copy link
Member

Yes, I'll do this right now

@simonjayhawkins
Copy link
Member

Thanks @jbrockmendel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants