Pandas version checks
-
[x] I have checked that this issue has not already been reported.
-
[x] I have confirmed this bug exists on the latest version of pandas.
-
[x] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import datetime as dt
import pandas as pd
dt.timedelta(days=1) * True # Works
pd.Timedelta("1 day") * True # Fails in 2.3.2 and in main
pd.Series([True, False]) * pd.timedelta_range(start="1 day", end="2 days") # Works in 2.3.2, fails in main
Issue Description
See above. Multiplying a bool times a Timedelta is inconsistent.
In version 2.3.2, you can't multiply a single bool and a pd.Timedelta object, but you can multiply them if they are in a Series.
In main ('3.0.0.dev0+2389.g452c7fb6a4'), you cannot multiply when in a Series.
Note that using datetime.timedelta, you can multiply a boolean with a Timedelta
Expected Behavior
I think multiplication of a Timedelta times a bool should work like it does for datetime.timedelta
Installed Versions
Comment From: Dr-Irv
@jbrockmendel I assigned to you - not sure if that is correct or not.
Comment From: jbrockmendel
We disabled that intentionally in #62248
Comment From: Dr-Irv
We disabled that intentionally in #62248
OK, but does it make sense that we can multiply dt.timedelta and bool, but not pd.Timedelta and bool ??
Comment From: jbrockmendel
i think it doesn't make sense that dt.timedelta*bool works.
Comment From: Dr-Irv
i think it doesn't make sense that dt.timedelta*bool works.
Well, we're then inconsistent with numpy as well:
>>> import numpy as np
>>> np.timedelta64(1, "D") * True
np.timedelta64(1,'D')
>>> np.timedelta64(1, "D") * False
np.timedelta64(0,'D')
My sense here is that if both python and numpy are supporting multiplying a bool times a timedelta, then pandas should do the same.
Comment From: PluvioXO
I am willing to implement this, will create a PR.
Comment From: cmp0xff
@Dr-Irv is it closed accidentally? It also seems to relate to pandas-dev/pandas#62552, hence I'll mention @jbrockmendel.
Comment From: Dr-Irv
@Dr-Irv is it closed accidentally? It also seems to relate to #62552, hence I'll mention @jbrockmendel.
I do think it is closed accidentally.