Skip to content

Commit 9c14725

Browse files
authored
TST: catch exception for div/truediv operations between Timedelta and pd.NA (#58188)
* *TST 54315 Add tests for pd.Timedelta and pd.NA div / truediv * Add release doc for TST 54315 * Apply pre commit correction for TST 54315 * "Correct bug fix description removed" * Remove unnecessary unit test description
1 parent 8bba1d4 commit 9c14725

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/scalar/timedelta/test_timedelta.py

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pytest
1212

1313
from pandas._libs import lib
14+
from pandas._libs.missing import NA
1415
from pandas._libs.tslibs import (
1516
NaT,
1617
iNaT,
@@ -138,6 +139,19 @@ def test_truediv_numeric(self, td):
138139
assert res._value == td._value / 2
139140
assert res._creso == td._creso
140141

142+
def test_truediv_na_type_not_supported(self, td):
143+
msg_td_floordiv_na = (
144+
r"unsupported operand type\(s\) for /: 'Timedelta' and 'NAType'"
145+
)
146+
with pytest.raises(TypeError, match=msg_td_floordiv_na):
147+
td / NA
148+
149+
msg_na_floordiv_td = (
150+
r"unsupported operand type\(s\) for /: 'NAType' and 'Timedelta'"
151+
)
152+
with pytest.raises(TypeError, match=msg_na_floordiv_td):
153+
NA / td
154+
141155
def test_floordiv_timedeltalike(self, td):
142156
assert td // td == 1
143157
assert (2.5 * td) // td == 2
@@ -182,6 +196,19 @@ def test_floordiv_numeric(self, td):
182196
assert res._value == td._value // 2
183197
assert res._creso == td._creso
184198

199+
def test_floordiv_na_type_not_supported(self, td):
200+
msg_td_floordiv_na = (
201+
r"unsupported operand type\(s\) for //: 'Timedelta' and 'NAType'"
202+
)
203+
with pytest.raises(TypeError, match=msg_td_floordiv_na):
204+
td // NA
205+
206+
msg_na_floordiv_td = (
207+
r"unsupported operand type\(s\) for //: 'NAType' and 'Timedelta'"
208+
)
209+
with pytest.raises(TypeError, match=msg_na_floordiv_td):
210+
NA // td
211+
185212
def test_addsub_mismatched_reso(self, td):
186213
# need to cast to since td is out of bounds for ns, so
187214
# so we would raise OverflowError without casting

0 commit comments

Comments
 (0)