python - Pandas invalid type comparison error -


for reason, can't find in pandas changelog 0.17.1, comparing datetime series int value (unix epoch) not work anymore. please explain or point me right section in changelog?

working in 0.16.2

>>> import pandas pd >>> import datetime >>> d = pd.series([datetime.datetime(2016, 1, 1), datetime.datetime(2016, 1, 1)]) >>> d 0   2016-01-01 1   2016-01-01 dtype: datetime64[ns] >>> d.dtype dtype('<m8[ns]') >>> d > 10 0    true 1    true dtype: bool 

error in 0.17.1

>>> import pandas pd >>> import datetime >>> d = pd.series([datetime.datetime(2016, 1, 1), datetime.datetime(2016, 1, 1)]) >>> d > 10 traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "/users/sven/tmp/pandastest/pandas-0.17.1/lib/python2.7/site-packages/pandas/core/ops.py", line 726, in wrapper     res = na_op(values, other)   file "/users/sven/tmp/pandastest/pandas-0.17.1/lib/python2.7/site-packages/pandas/core/ops.py", line 657, in na_op     raise typeerror("invalid type comparison") typeerror: invalid type comparison 

you can still use explicit conversion:

u_time_ns = d.apply(lambda x: x.to_datetime64().view('int64')) u_time_ns  0    1451606400000000000 1    1451606400000000000 dtype: int64  u_time_ns > 10  0    true 1    true dtype: bool 

or, if want rely on pandas timestamps being stored datetime64[ns]:

u_time_ns = d.view('int64') 

sorry, no idea why changed.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -