Skip to content

Unexpected exception on column with NaT #17559

Closed
@lebigot

Description

@lebigot

Code Sample

import pandas as pd
import datetime

# 4 examples:

df = pd.DataFrame({0: [1, None]})  # Works
df = pd.DataFrame({0: [None, 1]})  # Works

df = pd.DataFrame({0: [None, datetime.datetime.now()]})  # Exception

# Problem demonstration:
df != df.iloc[0]  # Works with numeric column, fails with NaT

Problem description & expected output.

In the above code, the final test raises an exception with the datetime example, but works with the two numeric examples.

I would expect the NaT case to behave like the numeric example.

Note: a column with datetimes but no NaT makes df != df.iloc[0] work as expected.

Expected Output

I expect the result to be, like for numeric values, a dataframe that answers the question "is the value identical to that in the first row?" (as a dataframe with the same shape).

Output of pd.show_versions()

<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.3
pytest: 3.2.2
pip: 9.0.1
setuptools: 36.3.0
Cython: 0.26.1
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.5.0a3
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions