Problem in comparisons for DataFrame with pd.NaT · Issue #22242 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd import datetime as dt

tmp = pd.DataFrame.from_records(data=[[dt.datetime(1999,12,31), pd.NaT], [pd.NaT, dt.datetime(1999,12,31)]]) print(tmp.iloc[0]==dt.datetime(1999,12,31)) print(tmp==dt.datetime(1999,12,31))

Output
(First print statement Series comparison)
0 True
1 False

(Second print statement DataFrame)
0 1
0 True True
1 True True

Problem description

When comparing a DataFrame containing pd.NaT (among other datetimes) with a single datetime results appears as True (second print statement).
This is different from the behaviour for Series (first print statement), which corresponds to what one would expect.

Expected Output

Second print statement should be
True False
False True

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

INSTALLED VERSIONS

commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-30-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: None
pip: 10.0.1
setuptools: 39.2.0
Cython: None
numpy: 1.15.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None