Skip to content

Commit 909ced4

Browse files
Remove some LSP sigs for _get_expected_exception
Test functions defined in `BaseArithmeticOpsTests` such as `test_arith_series_with_scalar` call `check_opname` which calls `_get_expected_exception`. Because `TestArithmetic` in `test_numpy.py` overrides `_get_expected_exception` and needs to access the `request` parameter, we need a mechanism to pass `request` down and back up the type hiearchy, which we can do using LSP style parameters `*args` and `**kwargs`. We could opt to do this consistently across all EA types, but since only `decimal/test_decimal.py` overrides, and because it doesn't actually use the `result` parameter, we instead simply omit `*args, **kwargs` when not needed. Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
1 parent 67e2dbc commit 909ced4

File tree

7 files changed

+16
-20
lines changed

7 files changed

+16
-20
lines changed

pandas/tests/extension/base/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BaseOpsUtil:
1919
divmod_exc: type[Exception] | None = TypeError
2020

2121
def _get_expected_exception(
22-
self, op_name: str, obj, other, *args, **kwargs
22+
self, op_name: str, obj, other
2323
) -> type[Exception] | None:
2424
# Find the Exception, if any we expect to raise calling
2525
# obj.__op_name__(other)

pandas/tests/extension/decimal/test_decimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def data_for_grouping():
6767

6868
class TestDecimalArray(base.ExtensionTests):
6969
def _get_expected_exception(
70-
self, op_name: str, obj, other, *args, **kwargs
70+
self, op_name: str, obj, other
7171
) -> type[Exception] | None:
7272
return None
7373

@@ -330,7 +330,7 @@ class TestArithmeticOps(base.BaseArithmeticOpsTests):
330330
series_array_exc = None
331331

332332
def _get_expected_exception(
333-
self, op_name: str, obj, other, *args, **kwargs
333+
self, op_name: str, obj, other
334334
) -> type[Exception] | None:
335335
return None
336336

pandas/tests/extension/test_arrow.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ def _is_temporal_supported(self, opname, pa_dtype):
938938
)
939939

940940
def _get_expected_exception(
941-
self, op_name: str, obj, other, *args, **kwargs
941+
self, op_name: str, obj, other
942942
) -> type[Exception] | None:
943943
if op_name in ("__divmod__", "__rdivmod__"):
944944
return self.divmod_exc
@@ -1048,9 +1048,7 @@ def test_arith_series_with_scalar(self, data, all_arithmetic_operators, request)
10481048
if mark is not None:
10491049
request.node.add_marker(mark)
10501050

1051-
super().test_arith_series_with_scalar(
1052-
data, all_arithmetic_operators, request=request
1053-
)
1051+
super().test_arith_series_with_scalar(data, all_arithmetic_operators)
10541052

10551053
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators, request):
10561054
pa_dtype = data.dtype.pyarrow_dtype
@@ -1064,9 +1062,7 @@ def test_arith_frame_with_scalar(self, data, all_arithmetic_operators, request):
10641062
if mark is not None:
10651063
request.node.add_marker(mark)
10661064

1067-
super().test_arith_frame_with_scalar(
1068-
data, all_arithmetic_operators, request=request
1069-
)
1065+
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
10701066

10711067
def test_arith_series_with_array(self, data, all_arithmetic_operators, request):
10721068
pa_dtype = data.dtype.pyarrow_dtype
@@ -1100,7 +1096,7 @@ def test_arith_series_with_array(self, data, all_arithmetic_operators, request):
11001096
# since ser.iloc[0] is a python scalar
11011097
other = pd.Series(pd.array([ser.iloc[0]] * len(ser), dtype=data.dtype))
11021098

1103-
self.check_opname(ser, op_name, other, request=request)
1099+
self.check_opname(ser, op_name, other)
11041100

11051101
def test_add_series_with_extension_array(self, data, request):
11061102
pa_dtype = data.dtype.pyarrow_dtype
@@ -1112,7 +1108,7 @@ def test_add_series_with_extension_array(self, data, request):
11121108
reason=f"raises on overflow for {pa_dtype}",
11131109
)
11141110
)
1115-
super().test_add_series_with_extension_array(data, request=request)
1111+
super().test_add_series_with_extension_array(data)
11161112

11171113
def test_invalid_other_comp(self, data, comparison_op):
11181114
# GH 48833

pandas/tests/extension/test_datetime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def cmp(a, b):
8383

8484
# ----------------------------------------------------------------------------
8585
class TestDatetimeArray(base.ExtensionTests):
86-
def _get_expected_exception(self, op_name, obj, other, *args, **kwargs):
86+
def _get_expected_exception(self, op_name, obj, other):
8787
if op_name in ["__sub__", "__rsub__"]:
8888
return None
89-
return super()._get_expected_exception(op_name, obj, other, *args, **kwargs)
89+
return super()._get_expected_exception(op_name, obj, other)
9090

9191
def _supports_accumulation(self, ser, op_name: str) -> bool:
9292
return op_name in ["cummin", "cummax"]

pandas/tests/extension/test_masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def data_for_grouping(dtype):
162162

163163

164164
class TestMaskedArrays(base.ExtensionTests):
165-
def _get_expected_exception(self, op_name, obj, other, *args, **kwargs):
165+
def _get_expected_exception(self, op_name, obj, other):
166166
try:
167167
dtype = tm.get_dtype(obj)
168168
except AttributeError:

pandas/tests/extension/test_period.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def data_for_grouping(dtype):
7272

7373

7474
class TestPeriodArray(base.ExtensionTests):
75-
def _get_expected_exception(self, op_name, obj, other, *args, **kwargs):
75+
def _get_expected_exception(self, op_name, obj, other):
7676
if op_name in ("__sub__", "__rsub__"):
7777
return None
78-
return super()._get_expected_exception(op_name, obj, other, *args, **kwargs)
78+
return super()._get_expected_exception(op_name, obj, other)
7979

8080
def _supports_accumulation(self, ser, op_name: str) -> bool:
8181
return op_name in ["cummin", "cummax"]

pandas/tests/extension/test_sparse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,11 @@ def _skip_if_different_combine(self, data):
383383

384384
def test_arith_series_with_scalar(self, data, all_arithmetic_operators, request):
385385
self._skip_if_different_combine(data)
386-
super().test_arith_series_with_scalar(data, all_arithmetic_operators, request)
386+
super().test_arith_series_with_scalar(data, all_arithmetic_operators)
387387

388388
def test_arith_series_with_array(self, data, all_arithmetic_operators, request):
389389
self._skip_if_different_combine(data)
390-
super().test_arith_series_with_array(data, all_arithmetic_operators, request)
390+
super().test_arith_series_with_array(data, all_arithmetic_operators)
391391

392392
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators, request):
393393
if data.dtype.fill_value != 0:
@@ -403,7 +403,7 @@ def test_arith_frame_with_scalar(self, data, all_arithmetic_operators, request):
403403
]:
404404
mark = pytest.mark.xfail(reason="result dtype.fill_value mismatch")
405405
request.node.add_marker(mark)
406-
super().test_arith_frame_with_scalar(data, all_arithmetic_operators, request)
406+
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
407407

408408

409409
class TestComparisonOps(BaseSparseTests):

0 commit comments

Comments
 (0)