Skip to content

Commit 4a73340

Browse files
remove unused stuff
1 parent c9e209e commit 4a73340

File tree

6 files changed

+41
-136
lines changed

6 files changed

+41
-136
lines changed

pandas/_libs/ops.pxd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ from numpy cimport int64_t
22

33

44
cpdef int64_t calc_int_int(object op, int64_t a, int64_t b) except? -1
5-
cpdef int64_t calc_int_float(object op, int64_t a, double b) except? -1

pandas/_libs/ops.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ def maybe_convert_bool(
4949
convert_to_masked_nullable: Literal[True],
5050
) -> tuple[np.ndarray, np.ndarray]: ...
5151
def calc_int_int(op, left: int, right: int) -> int: ...
52-
def calc_int_float(op, left: int, right: float) -> int: ...

pandas/_libs/ops.pyx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,3 @@ cpdef int64_t calc_int_int(object op, int64_t a, int64_t b) except? -1:
318318
operand or the result to an int64_t would overflow.
319319
"""
320320
return op(a, b)
321-
322-
@cython.overflowcheck(True)
323-
cpdef int64_t calc_int_float(object op, int64_t a, double b) except? -1:
324-
"""
325-
Calculate op(a, b) and return the result. Raises OverflowError if converting either
326-
operand or the result would overflow.
327-
"""
328-
return op(a, b)

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ cdef object ensure_td64ns(object ts):
250250

251251
unitstr = npy_unit_to_abbrev(td64_unit)
252252
mult = precision_from_unit(unitstr)[0]
253-
td64_value = calc_int_int(operator.mul, get_timedelta64_value(ts), mult)
253+
ns = calc_int_int(operator.mul, get_timedelta64_value(ts), mult)
254254

255-
return np.timedelta64(td64_value, "ns")
255+
return np.timedelta64(ns, "ns")
256256

257257

258258
cdef convert_to_timedelta64(object ts, str unit):
@@ -673,7 +673,7 @@ def _op_unary_method(func, name):
673673
return f
674674

675675

676-
cpdef int64_t calc_int_int(object op, object a, object b) except? -1:
676+
cdef int64_t calc_int_int(object op, object a, object b) except? -1:
677677
"""
678678
Calculate op(a, b), raising if either operand or the result cannot be safely cast
679679
to an int64_t.

pandas/tests/libs/test_ops.py

Lines changed: 24 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import operator
2-
from platform import architecture
32

43
import numpy as np
54
import pytest
65

76
from pandas._libs import ops
87

8+
from pandas.core.ops import (
9+
radd,
10+
rsub,
11+
)
12+
913

1014
@pytest.fixture(name="int_max", scope="module")
1115
def fixture_int_max() -> int:
@@ -17,16 +21,6 @@ def fixture_int_min() -> int:
1721
return np.iinfo(np.int64).min
1822

1923

20-
@pytest.fixture(name="float_max", scope="module")
21-
def fixture_float_max() -> np.float64:
22-
return np.finfo(np.float64).max
23-
24-
25-
@pytest.fixture(name="float_min", scope="module")
26-
def fixture_float_min() -> np.float64:
27-
return np.finfo(np.float64).min
28-
29-
3024
@pytest.fixture(name="overflow_msg", scope="module")
3125
def fixture_overflow_msg() -> str:
3226
return "|".join(
@@ -37,116 +31,37 @@ def fixture_overflow_msg() -> str:
3731
)
3832

3933

40-
class TestCalcIntInt:
41-
def test_raises_for_too_large_arg(self, int_max: int, overflow_msg: str):
42-
with pytest.raises(OverflowError, match=overflow_msg):
43-
ops.calc_int_int(operator.add, int_max + 1, 1)
44-
45-
with pytest.raises(OverflowError, match=overflow_msg):
46-
ops.calc_int_int(operator.add, 1, int_max + 1)
47-
48-
def test_raises_for_too_small_arg(self, int_min: int, overflow_msg: str):
49-
with pytest.raises(OverflowError, match=overflow_msg):
50-
ops.calc_int_int(operator.add, int_min - 1, 1)
34+
@pytest.fixture(name="add_op", params=(operator.add, radd))
35+
def fixture_add_op(request):
36+
return request.param
5137

52-
with pytest.raises(OverflowError, match=overflow_msg):
53-
ops.calc_int_int(operator.add, 1, int_min - 1)
5438

55-
def test_raises_for_too_large_result(self, int_max: int, overflow_msg: str):
56-
with pytest.raises(OverflowError, match=overflow_msg):
57-
ops.calc_int_int(operator.add, int_max, 1)
39+
@pytest.fixture(name="sub_op", params=(operator.sub, rsub))
40+
def fixture_sub_op(request):
41+
return request.param
5842

59-
with pytest.raises(OverflowError, match=overflow_msg):
60-
ops.calc_int_int(operator.add, 1, int_max)
6143

62-
def test_raises_for_too_small_result(self, int_min: int, overflow_msg: str):
63-
with pytest.raises(OverflowError, match=overflow_msg):
64-
ops.calc_int_int(operator.sub, int_min, 1)
44+
class TestCalcIntInt:
45+
def test_raises_for_too_large_arg(self, int_max: int, add_op, overflow_msg: str):
46+
add_op(int_max + 1, 1)
6547

6648
with pytest.raises(OverflowError, match=overflow_msg):
67-
ops.calc_int_int(operator.sub, 1, int_min)
49+
ops.calc_int_int(add_op, int_max + 1, 1)
6850

51+
def test_raises_for_too_small_arg(self, int_min: int, sub_op, overflow_msg: str):
52+
sub_op(int_min - 1, 1)
6953

70-
class TestCalcIntFloat:
71-
@pytest.mark.parametrize(
72-
"op,lval,rval,expected",
73-
(
74-
(operator.add, 1, 1.0, 2),
75-
(operator.sub, 2, 1.0, 1),
76-
(operator.mul, 1, 2.0, 2),
77-
(operator.truediv, 1, 0.5, 2),
78-
),
79-
ids=("+", "-", "*", "/"),
80-
)
81-
def test_arithmetic_ops(self, op, lval: int, rval: float, expected: int):
82-
result = ops.calc_int_float(op, lval, rval)
83-
84-
assert result == expected
85-
assert isinstance(result, int)
86-
87-
def test_raises_for_too_large_arg(
88-
self,
89-
int_max: int,
90-
float_max: float,
91-
overflow_msg: str,
92-
):
9354
with pytest.raises(OverflowError, match=overflow_msg):
94-
ops.calc_int_float(operator.add, int_max + 1, 1)
55+
ops.calc_int_int(sub_op, int_min - 1, 1)
9556

96-
with pytest.raises(OverflowError, match=overflow_msg):
97-
ops.calc_int_float(operator.add, 1, float_max + 1)
98-
99-
def test_raises_for_too_small_arg(
100-
self,
101-
int_min: int,
102-
float_min: float,
103-
overflow_msg: str,
104-
):
105-
with pytest.raises(OverflowError, match=overflow_msg):
106-
ops.calc_int_float(operator.add, int_min - 1, 1)
57+
def test_raises_for_too_large_result(self, int_max: int, add_op, overflow_msg: str):
58+
assert add_op(int_max, 1) == int_max + 1
10759

10860
with pytest.raises(OverflowError, match=overflow_msg):
109-
ops.calc_int_float(operator.add, 1, float_min - 1)
110-
111-
def test_raises_for_too_large_result(
112-
self,
113-
int_max: int,
114-
float_max: float,
115-
overflow_msg: str,
116-
):
117-
with pytest.raises(OverflowError, match=overflow_msg):
118-
ops.calc_int_float(operator.add, int_max, 1)
61+
ops.calc_int_int(add_op, int_max, 1)
11962

120-
with pytest.raises(OverflowError, match=overflow_msg):
121-
ops.calc_int_float(operator.add, 1, float_max)
63+
def test_raises_for_too_small_result(self, int_min: int, sub_op, overflow_msg: str):
64+
assert abs(sub_op(int_min, 1)) == abs(int_min - 1)
12265

123-
@pytest.mark.parametrize(
124-
"value",
125-
(
126-
pytest.param(
127-
1024,
128-
marks=pytest.mark.xfail(
129-
reason="TBD",
130-
raises=pytest.fail.Exception,
131-
strict=True,
132-
),
133-
),
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-
),
143-
),
144-
)
145-
def test_raises_for_most_too_small_results(
146-
self,
147-
value: float,
148-
int_min: int,
149-
overflow_msg: str,
150-
):
15166
with pytest.raises(OverflowError, match=overflow_msg):
152-
ops.calc_int_float(operator.sub, int_min, value)
67+
ops.calc_int_int(sub_op, int_min, 1)

pandas/tests/tslibs/test_timedeltas.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,27 @@ def test_delta_to_nanoseconds_error():
5353
delta_to_nanoseconds(np.int32(3))
5454

5555

56-
def test_huge_nanoseconds_overflow():
56+
def test_delta_to_nanoseconds_overflow():
5757
# GH 32402
5858
assert delta_to_nanoseconds(Timedelta(1e10)) == 1e10
5959
assert delta_to_nanoseconds(Timedelta(nanoseconds=1e10)) == 1e10
6060

6161

62-
class TestArrayToTimedelta64:
63-
def test_array_to_timedelta64_string_with_unit_2d_raises(self):
64-
# check the 'unit is not None and errors != "coerce"' path
65-
# in array_to_timedelta64 raises correctly with 2D values
66-
values = np.array([["1", 2], [3, "4"]], dtype=object)
67-
with pytest.raises(ValueError, match="unit must not be specified"):
68-
array_to_timedelta64(values, unit="s")
62+
def test_array_to_timedelta64_string_with_unit_2d_raises():
63+
# check the 'unit is not None and errors != "coerce"' path
64+
# in array_to_timedelta64 raises correctly with 2D values
65+
values = np.array([["1", 2], [3, "4"]], dtype=object)
66+
with pytest.raises(ValueError, match="unit must not be specified"):
67+
array_to_timedelta64(values, unit="s")
6968

70-
def test_array_to_timedelta64_non_object_raises(self):
71-
# check we raise, not segfault
72-
values = np.arange(5)
7369

74-
msg = "'values' must have object dtype"
75-
with pytest.raises(TypeError, match=msg):
76-
array_to_timedelta64(values)
70+
def test_array_to_timedelta64_non_object_raises():
71+
# check we raise, not segfault
72+
values = np.arange(5)
73+
74+
msg = "'values' must have object dtype"
75+
with pytest.raises(TypeError, match=msg):
76+
array_to_timedelta64(values)
7777

7878

7979
@pytest.mark.parametrize("unit", ["s", "ms", "us"])

0 commit comments

Comments
 (0)