Closed
Description
Related to #8306. On current master, Timestamp
comparison results in TypeError
if its timezones are different. However, Index
and Series
implicitly converts tz to GMT
pd.Timestamp('2016-01-01 12:00', tz='US/Eastern') > pd.Timestamp('2016-01-01 08:00')
# TypeError: Cannot compare tz-naive and tz-aware timestamps
# same result as idx.tz_convert(None) > pd.Timestamp('2016-01-01 08:00')
idx = pd.date_range('2016-01-01 12:00', periods=10, freq='H', tz='Asia/Tokyo')
idx > pd.Timestamp('2016-01-01 08:00')
# array([False, False, False, False, False, False, True, True, True, True], dtype=bool)
Numeric ops raises TypeError
as expected.
idx - pd.Timestamp('2016-01-01 08:00')
# TypeError: Timestamp subtraction must have the same timezones or no timezones
Activity
gliptak commentedon Mar 13, 2016
I opened numpy/numpy#7390 Does this belong to
pandas
instead? Thanksjreback commentedon Mar 13, 2016
this is an invalid dtype for numpy and not defined there
further what you are doing doesn't make any sense
gliptak commentedon Mar 13, 2016
@jreback I'm validating that the
ts
column hasdatetime64
with timezone (just comparing it todatetime64
fails ...). How would this need to be coded?jreback commentedon Mar 13, 2016
use
.select_dtypes
or ancom.is_datetimelike
orcom.is_datetime64tz_dtype
numpy doesn't know about/respect this (its really a bug in the dtype definition and i don't know when/if ever will be fixed/allowed).
jreback commentedon Mar 13, 2016
Here is also the method to coerce. EDT is not a timezone, and what
dateutil
is doing is wrong and doesn't give you anything useful.gliptak commentedon Mar 13, 2016
Thank you for the pointers.
So how am I to compare? Thanks
jreback commentedon Mar 13, 2016
what are you trying to do? why do you need to compare? what are you comparing? most ops will simply work, you rarely actually need to compare things, if you need to sub-select use
.select_dtypes(...)
as I indicated.gliptak commentedon Mar 13, 2016
Sorry, I didn't offer context. I came across this working unit tests for pydata/pandas-datareader#188
I had to force no timezone for the compare above to succeed ...
Could you show how to rewrite
df.dtypes['ts'] == np.dtype('datetime64[ns]')
with.select_dtypes(...)
?Thanks
jreback commentedon Mar 13, 2016
not really sure what you are doing
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.select_dtypes.html?highlight=select_dtypes#pandas.DataFrame.select_dtypes
15 remaining items