Skip to content

BUG: pd.to_timedelta raises instead of returning NaT #5437

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
danielballan opened this issue Nov 5, 2013 · 2 comments · Fixed by #5438
Closed

BUG: pd.to_timedelta raises instead of returning NaT #5437

danielballan opened this issue Nov 5, 2013 · 2 comments · Fixed by #5438
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type
Milestone

Comments

@danielballan
Copy link
Contributor

In [1]: Series(['2011-01-01', np.nan]).apply(pd.to_datetime)
Out[1]: 
0   2011-01-01 00:00:00
1                   NaT
dtype: datetime64[ns]

In [2]: Series(['00:00:01', np.nan]).apply(pd.to_timedelta)
AssertionError: Invalid type for timedelta scalar: <type 'float'>

May not be a trivial fix. So far I have seen that inserting np.nan and pd.tslib.iNaT into the result turns the dtype to object, which is no good.

@danielballan
Copy link
Contributor Author

That said, if this can be squeezed into 0.13, I'm willing to rush to get it done.

@jreback
Copy link
Contributor

jreback commented Nov 5, 2013

hmm though has done this oh well

it's easy just change this routine

coerce_scalar_to_timedelta_type(

in tseries/time delta

just need a isnull check and return tslib.iNaT
(it will work now if u pass NaT)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants