Skip to content

Commit b5e62d6

Browse files
misc. small fixes
1 parent 7a7418a commit b5e62d6

File tree

2 files changed

+58
-27
lines changed

2 files changed

+58
-27
lines changed

pandas/tests/libs/test_ops.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import operator
2+
from platform import architecture
23

34
import numpy as np
45
import pytest
@@ -17,12 +18,12 @@ def fixture_int_min() -> int:
1718

1819

1920
@pytest.fixture(name="float_max", scope="module")
20-
def fixture_float_max() -> int:
21+
def fixture_float_max() -> np.float64:
2122
return np.finfo(np.float64).max
2223

2324

2425
@pytest.fixture(name="float_min", scope="module")
25-
def fixture_float_min() -> int:
26+
def fixture_float_min() -> np.float64:
2627
return np.finfo(np.float64).min
2728

2829

@@ -130,7 +131,15 @@ def test_raises_for_too_large_result(
130131
strict=True,
131132
),
132133
),
133-
1024.1,
134+
pytest.param(
135+
1024.1,
136+
marks=pytest.mark.xfail(
137+
condition=architecture()[0] == "32bit",
138+
reason="overflows earlier",
139+
raises=pytest.fail.Exception,
140+
strict=True,
141+
),
142+
),
134143
),
135144
)
136145
def test_raises_for_most_too_small_results(

pandas/tests/scalar/timedelta/test_arithmetic.py

+46-24
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
timedelta,
1010
)
1111
import operator
12+
from platform import architecture
1213
import re
1314

1415
import numpy as np
1516
import pytest
1617

17-
from pandas._libs.tslibs import OutOfBoundsTimedelta
18+
from pandas._libs.tslibs import (
19+
NaTType,
20+
OutOfBoundsTimedelta,
21+
)
1822

1923
import pandas as pd
2024
from pandas import (
@@ -33,6 +37,7 @@ def fixture_tdlike_cls(request) -> type:
3337
return request.param
3438

3539

40+
# Tick, too?
3641
@pytest.fixture(
3742
name="tdlike_or_offset_cls",
3843
params=(Timedelta, timedelta, np.timedelta64, offsets.Nano),
@@ -148,8 +153,10 @@ def test_binary_ops_not_implemented_for_arbitrary_types(
148153

149154
class TestAdditionSubtractionScalar:
150155
"""
151-
Tests for Timedelta.{__add__,__radd__,__sub__,__rsub__} where second operand is a
152-
scalar.
156+
Tests against the following Timedelta methods, where second operand is a scalar:
157+
158+
__add__,__radd__,
159+
__sub__,__rsub__
153160
"""
154161

155162
@pytest.mark.parametrize(
@@ -230,7 +237,7 @@ def test_add_timedeltalike(self, ten_days: Timedelta, add_op, one_day):
230237
assert isinstance(result, Timedelta)
231238
assert result == expected
232239

233-
def test_sub_timedeltalike(self, ten_days: Timedelta, one_day, sub_op):
240+
def test_sub_timedeltalike(self, ten_days: Timedelta, sub_op, one_day):
234241
result = sub_op(ten_days, one_day)
235242
expected = Timedelta(days=9) if sub_op is operator.sub else Timedelta(days=-9)
236243
assert isinstance(result, Timedelta)
@@ -252,7 +259,7 @@ def test_sub_offset(self, ten_days: Timedelta, sub_op):
252259
assert isinstance(result, Timedelta)
253260
assert result == expected
254261

255-
def test_with_timedeltadlike_raises_for_any_result_above_td_max(
262+
def test_add_sub_tdlike_raises_for_any_result_above_td_max(
256263
self,
257264
tdlike_or_offset_cls,
258265
td_overflow_msg: str,
@@ -263,12 +270,12 @@ def test_with_timedeltadlike_raises_for_any_result_above_td_max(
263270
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
264271
Timedelta.max - (tdlike_or_offset_cls(-1))
265272

266-
def test_no_error_for_result_1ns_below_td_min(self):
273+
def test_add_sub_tdlike_raises_no_error_for_result_1ns_below_td_min(self):
267274
assert Timedelta.min + Timedelta(-1, "ns") is NaT
268275
assert offsets.Nano(-1) + Timedelta.min is NaT
269276
assert Timedelta.min - np.timedelta64(1, "ns") is NaT
270277

271-
def test_raises_for_any_result_2ns_below_td_min(
278+
def test_add_sub_tdlike_raises_for_any_result_2ns_below_td_min(
272279
self,
273280
tdlike_or_offset_cls: type,
274281
td_overflow_msg: str,
@@ -288,8 +295,11 @@ def test_add_or_sub_na(self, request, ten_days: Timedelta, add_or_sub, na_value)
288295

289296
class TestAdditionSubtractionBox:
290297
"""
291-
Tests for Timedelta.{__add__,__radd__,__sub__,__rsub__} where second operand is a
292-
Array/Index/Series/DataFrame.
298+
Tests against the following Timedelta methods, where second operand is a
299+
Array/Index/Series/DataFrame:
300+
301+
__add__,__radd__,
302+
__sub__,__rsub__
293303
"""
294304

295305
@pytest.mark.parametrize("value", (2, 2.0), ids=("int", "float"))
@@ -379,7 +389,9 @@ def test_na(self):
379389

380390
class TestMultiplicationScalar:
381391
"""
382-
Tests for Timedelta.{__mul__,__rmul__} where second operand is a scalar.
392+
Tests against the following Timedelta methods, where second operand is a scalar:
393+
394+
__mul__,__rmul__
383395
"""
384396

385397
@pytest.mark.parametrize(
@@ -419,8 +431,10 @@ def test_na(self, request, ten_days: Timedelta, mul_op, na_value):
419431

420432
class TestMultiplicationBox:
421433
"""
422-
Tests for Timedelta.{__mul__,__rmul__} where second operand is a
423-
Array/Index/Series/DataFrame.
434+
Tests against the following Timedelta methods, where second operand is a
435+
Array/Index/Series/DataFrame:
436+
437+
__mul__,__rmul__
424438
"""
425439

426440
@pytest.mark.parametrize("factor,expected", ((2, 20), (1.5, 15)))
@@ -433,13 +447,17 @@ def test_numeric(self, ten_days, mul_op, factor, expected, box_with_array):
433447
)
434448
tm.assert_equal(result, expected)
435449

436-
@pytest.mark.xfail(reason="no overflow check", raises=AssertionError)
450+
@pytest.mark.xfail(
451+
condition=architecture()[0] != "32bit",
452+
reason="no overflow check",
453+
raises=AssertionError,
454+
)
437455
@pytest.mark.parametrize("factor", (1.01, 2), ids=("int", "float"))
438456
def test_returns_nat_if_result_overflows(self, mul_op, factor, box_with_array):
439457
numeric_box = tm.box_expected((1, factor), box_with_array, transpose=False)
440-
result = mul_op(pd.Timedelta.max, numeric_box)
458+
result = mul_op(Timedelta.max, numeric_box)
441459
expected = tm.box_expected(
442-
(pd.Timedelta.max, NaT),
460+
(Timedelta.max, NaT),
443461
box_with_array,
444462
transpose=False,
445463
)
@@ -574,22 +592,25 @@ def test_offset(self, ten_days: Timedelta, div_op, expected):
574592
assert result == expected
575593

576594
def test_na(self, request, ten_days: Timedelta, truediv_op, na_value):
577-
expected = NaT
578-
if na_value is NA or (
595+
expected: NaTType | float = NaT
596+
597+
if na_value is None or na_value is NaT:
598+
expected = np.nan
599+
elif na_value is NA or (
579600
truediv_op is ops.rtruediv and isinstance(na_value, float)
580601
):
581602
request.applymarker(xfail_type_error)
582-
elif na_value is None or na_value is NaT:
583-
expected = np.nan
603+
584604
result = truediv_op(ten_days, na_value)
585605
assert result is expected
586606

587607
def test_floordiv_na(self, request, ten_days: Timedelta, na_value):
588-
expected = NaT
589-
if na_value is NA:
590-
request.applymarker(xfail_type_error)
591-
elif na_value is None or na_value is NaT:
608+
expected: NaTType | float = NaT
609+
610+
if na_value is None or na_value is NaT:
592611
expected = np.nan
612+
elif na_value is NA:
613+
request.applymarker(xfail_type_error)
593614

594615
result = ten_days // na_value
595616
assert result is expected
@@ -618,7 +639,8 @@ def test_rmod_na(self, request, ten_days: Timedelta, na_value):
618639
assert result is NaT
619640

620641
def test_divmod_na(self, request, ten_days: Timedelta, na_value):
621-
expected = (NaT, NaT)
642+
expected: tuple[NaTType | float, NaTType] = (NaT, NaT)
643+
622644
if na_value is None or na_value is NA:
623645
request.applymarker(xfail_type_error)
624646
elif na_value is NaT:

0 commit comments

Comments
 (0)