Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
BUG: comparisons fail for NaT in DataFrame #15697
Code Sample, a copy-pastable example if possible
>>> import pandas as pd >>> nat = pd.NaT >>> x = pd.Series([nat]) >>> x.eq(nat) 0 False dtype: bool >>> x == nat 0 False dtype: bool >>> y = pd.DataFrame(dict(x=x)) >>> y.eq(nat) x 0 NaT >>> y == nat x 0 True
Comparisons in a dataframe containing a single nat give incorrect answers. Note this occurs with both datetime and timedelta nats.
0 False dtype: bool 0 False dtype: bool x 0 False x 0 False
This is as expected,
actually you are right, this broken for dataframe for NaT, but works for np.nan.
so I'll mark it, though you should never do this. Maybe we should just raise.
Agreed; as above, the correct result of
Is there a reason why this call should never be made? At worst, we could just call
you don't want to compare against a null value, its not intuitive to do this as nan != nan is just plain confusing to most people.
The more explicit
So its not that you shouldn't do it if you know what you are doing, its just non-obvious from reading. Further it can provide lots of opportunities for odd bugs, consider.
this will give totally unexpected results.