-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: provide better error message for pd.Timedelta - pd.Series[Timestamp] #59571
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
Comments
Addition with these types is a communicate operation, but subtraction is not and is undefined even with analogous scalars from the standard library In [1]: import datetime
In [2]: datetime.timedelta(1) - datetime.datetime.now()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 datetime.timedelta(1) - datetime.datetime.now()
TypeError: unsupported operand type(s) for -: 'datetime.timedelta' and 'datetime.datetime'
In [3]: import pandas as pd
In [4]: pd.Timedelta(1) - pd.Timestamp.now()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 1
----> 1 pd.Timedelta(1) - pd.Timestamp.now()
TypeError: unsupported operand type(s) for -: 'Timedelta' and 'Timestamp' |
@mroeschke yes, now that I think about it, this operation doesn't make sense in pandas either. However, the error message |
Agreed that it would be nice to have a clearer error message (renamed/relabeled the issue as such) |
Take |
@KevsterAmp Still working on this issue or can I assign it to myself? |
You can assign it to yourself. @AshmitGupta |
Will be going to continue to work on this |
take |
take |
take |
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
You can do the same subtraction with integers (
1 - pd.Series(10)
), and you can also dopd.Timedelta + pd.Series[Timestamp]
(pd.Timedelta(10) + pd.Series([pd.Timestamp(1)])
), so pandas should be consistent and allowpd.Timedelta - pd.Series[Timestamp]
#25497 is an older, closed issue about the error message here, but this scenario shouldn't cause an error at all.
Expected Behavior
Should subtract the scalar from each element of the series/dataframe/index
Installed Versions
The text was updated successfully, but these errors were encountered: