Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: comparing 'NaT' in series with series returns True #9005

Closed
jorisvandenbossche opened this issue Dec 4, 2014 · 9 comments · Fixed by #13592
Closed

BUG: comparing 'NaT' in series with series returns True #9005

jorisvandenbossche opened this issue Dec 4, 2014 · 9 comments · Fixed by #13592
Labels
Bug Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@jorisvandenbossche
Copy link
Member

xref #12877 (test on Series & DataFrame)

When having a 'NaT' in a datetime series and comparing this to a datetime series, the comparison with NaT returns True (and shouldn't comparisons with NA not always return False?) Comparing it with a scalar does return False:

In [54]: s = pd.Series([pd.Timestamp('2012-01-01'), pd.Timestamp('NaT')])
In [55]: s2 = pd.Series([pd.Timestamp('2013-01-01'), pd.Timestamp('2014-01-01')])

In [57]: s
Out[57]:
0   2012-01-01
1          NaT
dtype: datetime64[ns]

In [58]: s2
Out[58]:
0   2013-01-01
1   2014-01-01
dtype: datetime64[ns]

In [59]: s < s2
Out[59]:
0    True
1    True
dtype: bool

In [60]: s < pd.Timestamp('2013-01-01')
Out[60]:
0     True
1    False
dtype: bool

Original from http://stackoverflow.com/questions/27305324/pandas-comparison-with-variable-number-of-columns/27305661#27305661

@jreback
Copy link
Contributor

jreback commented Dec 4, 2014

hmm that looks wrong for series; yep should compare as False

@jreback jreback added Bug Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions labels Dec 4, 2014
@jreback jreback added this to the 0.16.0 milestone Dec 4, 2014
@jorisvandenbossche
Copy link
Member Author

Greater than does return False:

In [68]: s > s2
Out[68]:
0    False
1    False
dtype: bool

@jreback
Copy link
Contributor

jreback commented Dec 4, 2014

yep because its comparing the actual value (and not using `_maybe_mask_results()`` (method) after

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@cfperez
Copy link
Contributor

cfperez commented Apr 6, 2016

Hey @jreback, this bug just bit me in 0.18.0. Just pinging to put back on the radar.

@jreback
Copy link
Contributor

jreback commented Apr 6, 2016

@cfperez pull-requests are welcome here.

@jreback
Copy link
Contributor

jreback commented Apr 6, 2016

This is in 0.18.0; all of which looks correct, e.g. comparison with NaT all return False

In [1]:  s = pd.Series([pd.Timestamp('2012-01-01'), pd.Timestamp('NaT')])

In [2]:  s2 = pd.Series([pd.Timestamp('2013-01-01'), pd.Timestamp('2014-01-01')])

In [3]: s == s2
Out[3]: 
0    False
1    False
dtype: bool

In [4]: s < s2
Out[4]: 
0     True
1    False
dtype: bool

In [5]: s < pd.Timestamp('2014-01-01')
Out[5]: 
0     True
1    False
dtype: bool

In [6]: s2 < s
Out[6]: 
0    False
1    False
dtype: bool

In [7]: pd.Timestamp('2014-01-01') < s
Out[7]: 
0    False
1    False
dtype: bool

@cfperez are [4] and [5] not returning like the above?

@jreback jreback modified the milestones: 0.18.1, Next Major Release Apr 6, 2016
@jreback
Copy link
Contributor

jreback commented Apr 6, 2016

@sinhrks has been fixing lots of these NaT issues. so this looks fixed. just need confirming tests.

@cfperez
Copy link
Contributor

cfperez commented Apr 6, 2016

I'll see what I can do! Working on #10668 first.

On Wed, 6 Apr 2016, 9:29 AM Jeff Reback notifications@github.com wrote:

@cfperez https://github.com/cfperez pull-requests are welcome here.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#9005 (comment)

@jreback
Copy link
Contributor

jreback commented Apr 6, 2016

@cfperez gr8!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants