Skip to content

unexpected timestamps behavior #19725

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

Closed
bordingj opened this issue Feb 16, 2018 · 1 comment
Closed

unexpected timestamps behavior #19725

bordingj opened this issue Feb 16, 2018 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@bordingj
Copy link

bordingj commented Feb 16, 2018

If I run

pd.to_datetime('now') == pd.to_datetime('now', utc=True)

or

pd.Timestamp('now', tz='utc') == pd.Timestamp('now')

I get

TypeError: Cannot compare tz-naive and tz-aware timestamps

which makes sense.

However if I compare a tz-naive DatetimeIndex og Series with a tz-aware timestamp I dont get an error

In[1]: date
Out[1]: Timestamp('2016-01-05 00:00:00+0000', tz='UTC')

In[2]: pd.to_datetime(['2012-01-06T00:00:00.000000000', '2013-01-08T00:00:00.000000000',
                '2014-01-07T00:00:00.000000000', '2015-01-06T00:00:00.000000000',
                '2016-01-05T00:00:00.000000000']) == date
Out[2]: array([False, False, False, False,  True])

In[3]: pd.Series(pd.to_datetime(['2012-01-06T00:00:00.000000000', '2013-01-08T00:00:00.000000000',
                '2014-01-07T00:00:00.000000000', '2015-01-06T00:00:00.000000000',
                '2016-01-05T00:00:00.000000000'])) == date
Out[3]: 
0    False
1    False
2    False
3    False
4     True
dtype: bool

and if I compare a datetime64[ns] numpy array to the tz-aware timestamp I also dont get an error, plus I get wrong results:

In[4]: pd.to_datetime(['2012-01-06T00:00:00.000000000', '2013-01-08T00:00:00.000000000',
                '2014-01-07T00:00:00.000000000', '2015-01-06T00:00:00.000000000',
                '2016-01-05T00:00:00.000000000']).values == date
Out[4]: array([False, False, False, False, False])

I am running:
pandas: 0.22.0
numpy: 1.14.0
pytz: 2017.3
python: 3.6.3

on ubuntu 16.04

@TomAugspurger
Copy link
Contributor

There's been a lot of work on this recently. Comparing a tz-naive and tz-aware datetimeindex now raises on master: #18376

@TomAugspurger TomAugspurger added the Duplicate Report Duplicate issue or pull request label Feb 16, 2018
@TomAugspurger TomAugspurger added this to the No action milestone Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants