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
Given that the Timedelta itself seems to support arithmetic with scalar strings, it seems that dataframes and series of timedelta should support arithmetic with strings or data structures containing strings.
sfc-gh-mvashishtha
changed the title
BUG: some cases of adding string to timedelta raise TypeError
BUG: some cases of binary arithmetic between string and timedelta raise TypeError
Aug 29, 2024
Also, some operators don't work, e.g. pd.Series(['1']) + pd.Timedelta(1) and pd.Series(['1']) == pd.Timedelta(1) work, but pd.Series(['1']) <= pd.Timedelta(1) does not
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The example above should produce
pd.Series(pd.Timedelta(2))
, but it raises aTypeError
instead.There are some other cases that don't work either:
pd.Series(['1']) + pd.Series(pd.Timedelta(1))
pd.Timedelta(1) + pd.Series(['1'])
pd.Series(pd.Timedelta(1)) + '1'
'1' + pd.Series(pd.Timedelta(1))
pd.Timedelta(1) + pd.Series('1')
But some cases that do:
pd.DataFrame(['1']) + pd.DataFrame([pd.Timedelta(1)])
pd.DataFrame([pd.Timedelta(1)]) + pd.DataFrame(['1'])
pd.Series(['1']) + pd.Timedelta(1)
pd.Series('1') + pd.Timedelta(1)
Expected Behavior
Given that the
Timedelta
itself seems to support arithmetic with scalar strings, it seems that dataframes and series of timedelta should support arithmetic with strings or data structures containing strings.Installed Versions
The text was updated successfully, but these errors were encountered: