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
Comment From: TomAugspurger
There's been a lot of work on this recently. Comparing a tz-naive and tz-aware datetimeindex now raises on master: https://github.com/pandas-dev/pandas/pull/18376