Unexpected exception on column with NaT
See original GitHub issueCode 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>
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
python - pandas issue with pandas.NaT when changing from ...
In this case, I would do type(df.loc[knownnatdata) and use that as input for the method. For example, I filled a dataframe column with...
Read more >Plotting a Spatially Enabled DataFrame w/ datetime...
This seems to only be an issue if all the values in a datetime column are NaT. I won't go into details why,...
Read more >issue with uturn nat, please help! - LIVEcommunity - 25028
Hi All I have a u turn nat rule and security policy in place that has been working fine to allow internal access...
Read more >Troubleshoot NAT gateways - Amazon Virtual Private Cloud
To view the error message, open the Amazon VPC console, and then choose NAT Gateways. Select the radio button for your NAT gateway,...
Read more >Looker error catalog | Google Cloud
Query failed with unexpected exception (?), IDE Ex SQL LD D S. A database other than the main connection database is specified in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So the fact that seems to make the difference is that here you are comparing to a Series, and not a scalar (the scalar case works ‘fine’, except from the behavioural bug from https://github.com/pandas-dev/pandas/issues/15697 that it should be False instead of True):
Looks like the following test was added in /pandas/tests/arithmetic/test_datetime64.py, as part of GH22163. Would it cover this issue sufficiently already, or should anything else be tested?