|
11 | 11 | from pandas._libs.tslibs import timezones
|
12 | 12 | from pandas.compat import WASM
|
13 | 13 | from pandas.errors import OutOfBoundsDatetime
|
| 14 | +import pandas.util._test_decorators as td |
14 | 15 |
|
15 | 16 | import pandas as pd
|
16 | 17 | from pandas import (
|
@@ -1556,6 +1557,51 @@ def test_tdi_rmul_arraylike(self, other, box_with_array):
|
1556 | 1557 | commute = tdi * other
|
1557 | 1558 | tm.assert_equal(commute, expected)
|
1558 | 1559 |
|
| 1560 | + def test_td64arr_mul_bool_scalar_raises(self, box_with_array): |
| 1561 | + # GH#58054 |
| 1562 | + ser = Series(np.arange(5) * timedelta(hours=1)) |
| 1563 | + obj = tm.box_expected(ser, box_with_array) |
| 1564 | + |
| 1565 | + msg = r"Cannot multiply 'timedelta64\[ns\]' by bool" |
| 1566 | + with pytest.raises(TypeError, match=msg): |
| 1567 | + True * obj |
| 1568 | + with pytest.raises(TypeError, match=msg): |
| 1569 | + obj * True |
| 1570 | + with pytest.raises(TypeError, match=msg): |
| 1571 | + np.True_ * obj |
| 1572 | + with pytest.raises(TypeError, match=msg): |
| 1573 | + obj * np.True_ |
| 1574 | + |
| 1575 | + @pytest.mark.parametrize( |
| 1576 | + "dtype", |
| 1577 | + [ |
| 1578 | + bool, |
| 1579 | + "boolean", |
| 1580 | + pytest.param("bool[pyarrow]", marks=td.skip_if_no("pyarrow")), |
| 1581 | + ], |
| 1582 | + ) |
| 1583 | + def test_td64arr_mul_bool_raises(self, dtype, box_with_array): |
| 1584 | + # GH#58054 |
| 1585 | + ser = Series(np.arange(5) * timedelta(hours=1)) |
| 1586 | + obj = tm.box_expected(ser, box_with_array) |
| 1587 | + |
| 1588 | + other = Series(np.arange(5) < 0.5, dtype=dtype) |
| 1589 | + other = tm.box_expected(other, box_with_array) |
| 1590 | + |
| 1591 | + msg = r"Cannot multiply 'timedelta64\[ns\]' by bool" |
| 1592 | + with pytest.raises(TypeError, match=msg): |
| 1593 | + obj * other |
| 1594 | + |
| 1595 | + msg2 = msg.replace("rmul", "mul") |
| 1596 | + if dtype == "bool[pyarrow]": |
| 1597 | + # We go through ArrowEA.__mul__ which gives a different message |
| 1598 | + msg2 = ( |
| 1599 | + r"operation 'mul' not supported for dtype 'bool\[pyarrow\]' " |
| 1600 | + r"with dtype 'timedelta64\[ns\]'" |
| 1601 | + ) |
| 1602 | + with pytest.raises(TypeError, match=msg2): |
| 1603 | + other * obj |
| 1604 | + |
1559 | 1605 | # ------------------------------------------------------------------
|
1560 | 1606 | # __div__, __rdiv__
|
1561 | 1607 |
|
|
0 commit comments