DataFrame of datetimes with NaT Comparison always evaluates to True · Issue #12877 · pandas-dev/pandas (original) (raw)

Code Sample

>>> import pandas as pd
>>> from datetime import date
>>> df=pd.DataFrame({'a': pd.Series([date(2016,1,1)], index=[date(2016,1,1)]), 'b': pd.Series([date(2016,1,3)], index=[date(2016,1,3)])})
>>> df
                     a           b
2016-01-01  2016-01-01         NaN
2016-01-03         NaN  2016-01-03
>>> df>date(2016,1,2)
               a     b
2016-01-01  True  True
2016-01-03  True  True
>>> df<date(2016,1,2)
               a     b
2016-01-01  True  True
2016-01-03  True  True

Expected Output

something more like with NaT:

>>> df.fillna(pd.NaT, inplace=True)
>>> df>date(2016,1,2)
                a      b
2016-01-01  False  False
2016-01-03  False   True
>>> df<date(2016,1,2)
                a      b
2016-01-01   True  False
2016-01-03  False  False

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Linux
OS-release: 4.2.0-22-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.0
nose: 1.3.6
pip: 1.5.6
setuptools: 18.4
Cython: None
numpy: 1.8.2
scipy: 0.14.1
statsmodels: 0.5.0
xarray: None
IPython: 2.3.0
sphinx: None
patsy: 0.4.0
dateutil: 2.2
pytz: 2014.10
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.3
matplotlib: 1.4.2
openpyxl: 2.3.0-b1
xlrd: 0.9.4
xlwt: 0.7.5
xlsxwriter: None
lxml: 3.4.4
bs4: 4.3.2
html5lib: 0.999
httplib2: 0.9
apiclient: None
sqlalchemy: None
pymysql: 0.6.2.None
psycopg2: None
jinja2: 2.8
boto: None