You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# set up a dataframe with a datetime value in itfromdatetimeimportdatetimeimportpandasaspddf=pd.DataFrame({'foo' : [datetime.now()] })
printdf.dtypes# =>foodatetime64[ns]
dtype: object# let's convert to timedeltadf.foo.apply(lambdar : timedelta(hours=r.hour, minutes=r.minute, seconds=r.second, microseconds=r.microseconds))
=>TypeError: unsupportedtypefortimedeltamicrosecondscomponent: numpy.int32
Expected:
# no excepetions, whatever the correct valuedf.foo.apply(lambdar : timedelta(hours=r.hour, minutes=r.minute, seconds=r.second, microseconds=r.microseconds))
# => 016:08:25.347571Name: foo, dtype: timedelta64[ns]
Work around:
# if you can't control the timedelta conversion (i.e. it is somewhere embedded, e.g. in a library)df.foo=df.foo.astype(datetime)
# if you candf.foo.apply(lambdar : timedelta(hours=r.hour, minutes=r.minute, seconds=r.second, microseconds=int(r.microseconds))
Some Timestamp properties return np.int32, and if these are passed to a logic like isinstance(x, int) should fail. Every properties should return int, @jreback?
Using Pandas' datetime64 dtype to convert to a datetime.timedelta object results in this type error:
Reproduce:
Expected:
Work around:
Version information
The text was updated successfully, but these errors were encountered: