diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 8343d51dcb4f1..4d30415a396db 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -83,6 +83,7 @@ from pandas._libs.tslibs.offsets import Day from pandas._libs.tslibs.util cimport ( is_array, + is_bool_object, is_float_object, is_integer_object, ) @@ -2311,6 +2312,13 @@ class Timedelta(_Timedelta): return self.__mul__(item) return other * self.to_timedelta64() + elif is_bool_object(other): + # GH#62316 + raise TypeError( + "Cannot multiply Timedelta by bool. " + "Explicitly cast to integer instead." + ) + return NotImplemented __rmul__ = __mul__ diff --git a/pandas/tests/scalar/timedelta/test_arithmetic.py b/pandas/tests/scalar/timedelta/test_arithmetic.py index 6f7f2a339d944..1f6ece9f3e8f1 100644 --- a/pandas/tests/scalar/timedelta/test_arithmetic.py +++ b/pandas/tests/scalar/timedelta/test_arithmetic.py @@ -970,6 +970,12 @@ def test_td_op_timedelta_timedeltalike_array(self, op, arr): with pytest.raises(TypeError, match=msg): op(arr, Timedelta("1D")) + def test_mul_bool_invalid(self): + # GH#62316 + msg = "Cannot multiply Timedelta by bool. Explicitly cast to integer" + with pytest.raises(TypeError, match=msg): + Timedelta("1 day") * True + class TestTimedeltaComparison: def test_compare_pytimedelta_bounds(self):