Skip to content

Commit c9c6685

Browse files
authored
TYP: pandas/_testing (#47037)
* TYP: bunch of type annotations * change not needed
1 parent 68c439b commit c9c6685

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

pandas/_testing/_warnings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import re
88
import sys
99
from typing import (
10+
Literal,
1011
Sequence,
1112
Type,
1213
cast,
@@ -17,7 +18,9 @@
1718
@contextmanager
1819
def assert_produces_warning(
1920
expected_warning: type[Warning] | bool | None = Warning,
20-
filter_level="always",
21+
filter_level: Literal[
22+
"error", "ignore", "always", "default", "module", "once"
23+
] = "always",
2124
check_stacklevel: bool = True,
2225
raise_on_extra_warnings: bool = True,
2326
match: str | None = None,

pandas/_testing/asserters.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import cast
3+
from typing import (
4+
Literal,
5+
cast,
6+
)
47
import warnings
58

69
import numpy as np
@@ -10,6 +13,7 @@
1013
no_default,
1114
)
1215
from pandas._libs.missing import is_matching_na
16+
from pandas._libs.sparse import SparseIndex
1317
import pandas._libs.testing as _testing
1418
from pandas.util._exceptions import find_stack_level
1519

@@ -61,7 +65,7 @@
6165
def assert_almost_equal(
6266
left,
6367
right,
64-
check_dtype: bool | str = "equiv",
68+
check_dtype: bool | Literal["equiv"] = "equiv",
6569
check_less_precise: bool | int | NoDefault = no_default,
6670
rtol: float = 1.0e-5,
6771
atol: float = 1.0e-8,
@@ -164,9 +168,8 @@ def assert_almost_equal(
164168
assert_class_equal(left, right, obj=obj)
165169

166170
# if we have "equiv", this becomes True
167-
check_dtype = bool(check_dtype)
168171
_testing.assert_almost_equal(
169-
left, right, check_dtype=check_dtype, rtol=rtol, atol=atol, **kwargs
172+
left, right, check_dtype=bool(check_dtype), rtol=rtol, atol=atol, **kwargs
170173
)
171174

172175

@@ -676,7 +679,7 @@ def assert_numpy_array_equal(
676679
left,
677680
right,
678681
strict_nan=False,
679-
check_dtype=True,
682+
check_dtype: bool | Literal["equiv"] = True,
680683
err_msg=None,
681684
check_same=None,
682685
obj="numpy array",
@@ -755,7 +758,7 @@ def _raise(left, right, err_msg):
755758
def assert_extension_array_equal(
756759
left,
757760
right,
758-
check_dtype=True,
761+
check_dtype: bool | Literal["equiv"] = True,
759762
index_values=None,
760763
check_less_precise=no_default,
761764
check_exact=False,
@@ -848,7 +851,7 @@ def assert_extension_array_equal(
848851
_testing.assert_almost_equal(
849852
left_valid,
850853
right_valid,
851-
check_dtype=check_dtype,
854+
check_dtype=bool(check_dtype),
852855
rtol=rtol,
853856
atol=atol,
854857
obj="ExtensionArray",
@@ -860,7 +863,7 @@ def assert_extension_array_equal(
860863
def assert_series_equal(
861864
left,
862865
right,
863-
check_dtype=True,
866+
check_dtype: bool | Literal["equiv"] = True,
864867
check_index_type="equiv",
865868
check_series_type=True,
866869
check_less_precise=no_default,
@@ -1054,7 +1057,7 @@ def assert_series_equal(
10541057
right._values,
10551058
rtol=rtol,
10561059
atol=atol,
1057-
check_dtype=check_dtype,
1060+
check_dtype=bool(check_dtype),
10581061
obj=str(obj),
10591062
index_values=np.asarray(left.index),
10601063
)
@@ -1090,7 +1093,7 @@ def assert_series_equal(
10901093
right._values,
10911094
rtol=rtol,
10921095
atol=atol,
1093-
check_dtype=check_dtype,
1096+
check_dtype=bool(check_dtype),
10941097
obj=str(obj),
10951098
index_values=np.asarray(left.index),
10961099
)
@@ -1115,7 +1118,7 @@ def assert_series_equal(
11151118
def assert_frame_equal(
11161119
left,
11171120
right,
1118-
check_dtype=True,
1121+
check_dtype: bool | Literal["equiv"] = True,
11191122
check_index_type="equiv",
11201123
check_column_type="equiv",
11211124
check_frame_type=True,
@@ -1393,8 +1396,8 @@ def assert_sp_array_equal(left, right):
13931396
assert_numpy_array_equal(left.sp_values, right.sp_values)
13941397

13951398
# SparseIndex comparison
1396-
assert isinstance(left.sp_index, pd._libs.sparse.SparseIndex)
1397-
assert isinstance(right.sp_index, pd._libs.sparse.SparseIndex)
1399+
assert isinstance(left.sp_index, SparseIndex)
1400+
assert isinstance(right.sp_index, SparseIndex)
13981401

13991402
left_index = left.sp_index
14001403
right_index = right.sp_index

pandas/util/_test_decorators.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_foo():
3535

3636
from pandas._config import get_option
3737

38+
from pandas._typing import F
3839
from pandas.compat import (
3940
IS64,
4041
is_platform_windows,
@@ -216,7 +217,7 @@ def skip_if_np_lt(ver_str: str, *args, reason: str | None = None):
216217
)
217218

218219

219-
def parametrize_fixture_doc(*args):
220+
def parametrize_fixture_doc(*args) -> Callable[[F], F]:
220221
"""
221222
Intended for use as a decorator for parametrized fixture,
222223
this function will wrap the decorated function with a pytest

0 commit comments

Comments
 (0)