|
| 1 | +from datetime import timedelta |
| 2 | + |
1 | 3 | import numpy as np |
2 | 4 | import pytest |
3 | 5 |
|
@@ -90,6 +92,53 @@ def test_add_pdnat(self, tda): |
90 | 92 | assert result._reso == tda._reso |
91 | 93 | assert result.isna().all() |
92 | 94 |
|
| 95 | + def test_mul_scalar(self, tda): |
| 96 | + other = 2 |
| 97 | + result = tda * other |
| 98 | + expected = TimedeltaArray._simple_new(tda._ndarray * other, dtype=tda.dtype) |
| 99 | + tm.assert_extension_array_equal(result, expected) |
| 100 | + assert result._reso == tda._reso |
| 101 | + |
| 102 | + def test_mul_listlike(self, tda): |
| 103 | + other = np.arange(len(tda)) |
| 104 | + result = tda * other |
| 105 | + expected = TimedeltaArray._simple_new(tda._ndarray * other, dtype=tda.dtype) |
| 106 | + tm.assert_extension_array_equal(result, expected) |
| 107 | + assert result._reso == tda._reso |
| 108 | + |
| 109 | + def test_mul_listlike_object(self, tda): |
| 110 | + other = np.arange(len(tda)) |
| 111 | + result = tda * other.astype(object) |
| 112 | + expected = TimedeltaArray._simple_new(tda._ndarray * other, dtype=tda.dtype) |
| 113 | + tm.assert_extension_array_equal(result, expected) |
| 114 | + assert result._reso == tda._reso |
| 115 | + |
| 116 | + def test_div_numeric_scalar(self, tda): |
| 117 | + other = 2 |
| 118 | + result = tda / other |
| 119 | + expected = TimedeltaArray._simple_new(tda._ndarray / other, dtype=tda.dtype) |
| 120 | + tm.assert_extension_array_equal(result, expected) |
| 121 | + assert result._reso == tda._reso |
| 122 | + |
| 123 | + def test_div_td_scalar(self, tda): |
| 124 | + other = timedelta(seconds=1) |
| 125 | + result = tda / other |
| 126 | + expected = tda._ndarray / np.timedelta64(1, "s") |
| 127 | + tm.assert_numpy_array_equal(result, expected) |
| 128 | + |
| 129 | + def test_div_numeric_array(self, tda): |
| 130 | + other = np.arange(len(tda)) |
| 131 | + result = tda / other |
| 132 | + expected = TimedeltaArray._simple_new(tda._ndarray / other, dtype=tda.dtype) |
| 133 | + tm.assert_extension_array_equal(result, expected) |
| 134 | + assert result._reso == tda._reso |
| 135 | + |
| 136 | + def test_div_td_array(self, tda): |
| 137 | + other = tda._ndarray + tda._ndarray[-1] |
| 138 | + result = tda / other |
| 139 | + expected = tda._ndarray / other |
| 140 | + tm.assert_numpy_array_equal(result, expected) |
| 141 | + |
93 | 142 |
|
94 | 143 | class TestTimedeltaArray: |
95 | 144 | @pytest.mark.parametrize("dtype", [int, np.int32, np.int64, "uint32", "uint64"]) |
|
0 commit comments