Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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__
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down