|
25 | 25 | TYPE_CHECKING, |
26 | 26 | Any, |
27 | 27 | Generic, |
28 | | - Protocol, |
29 | 28 | TypeAlias, |
30 | 29 | TypedDict, |
31 | 30 | TypeVar, |
|
72 | 71 |
|
73 | 72 | if TYPE_CHECKING: |
74 | 73 | from pandas.core.frame import _PandasNamedTuple |
| 74 | + |
| 75 | + from pandas._typing import S1 |
75 | 76 | else: |
76 | 77 | _PandasNamedTuple: TypeAlias = tuple |
77 | 78 |
|
@@ -828,7 +829,9 @@ def test_dataframe_clip() -> None: |
828 | 829 | df.clip(lower=pd.Series([1, 2]), upper=pd.Series([4, 5]), axis=None) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType] |
829 | 830 | df.copy().clip(lower=pd.Series([1, 2]), upper=None, axis=None, inplace=True) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType] |
830 | 831 | df.copy().clip(lower=None, upper=pd.Series([1, 2]), axis=None, inplace=True) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType] |
831 | | - df.copy().clip(lower=pd.Series([4, 5]), upper=pd.Series([1, 2]), axis=None, inplace=True) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType] |
| 832 | + df.copy().clip( |
| 833 | + lower=pd.Series([4, 5]), upper=pd.Series([1, 2]), axis=None, inplace=True |
| 834 | + ) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType] |
832 | 835 |
|
833 | 836 | check( |
834 | 837 | assert_type(df.clip(lower=None, upper=None, axis=None), pd.DataFrame), |
@@ -1713,12 +1716,7 @@ def test_types_groupby_agg() -> None: |
1713 | 1716 | agg_dict1 = {"col2": "min", "col3": "max", 0: "sum"} |
1714 | 1717 | check(assert_type(df.groupby("col1").agg(agg_dict1), pd.DataFrame), pd.DataFrame) |
1715 | 1718 |
|
1716 | | - T_co = TypeVar("T_co", covariant=True) |
1717 | | - |
1718 | | - class SupportsMin(Protocol[T_co]): |
1719 | | - def min(self) -> T_co: ... |
1720 | | - |
1721 | | - def wrapped_min(x: SupportsMin[T_co]) -> T_co: |
| 1719 | + def wrapped_min(x: pd.Series[S1]) -> S1: |
1722 | 1720 | return x.min() |
1723 | 1721 |
|
1724 | 1722 | with pytest_warns_bounded( |
@@ -4313,10 +4311,24 @@ def test_to_dict_index() -> None: |
4313 | 4311 | assert_type(df.to_dict(orient="split", index=False), dict[str, list]), dict, str |
4314 | 4312 | ) |
4315 | 4313 | if TYPE_CHECKING_INVALID_USAGE: |
4316 | | - check(assert_type(df.to_dict(orient="records", index=False), list[dict[Hashable, Any]]), list) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
4317 | | - check(assert_type(df.to_dict(orient="dict", index=False), dict[Hashable, Any]), dict) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
4318 | | - check(assert_type(df.to_dict(orient="series", index=False), dict[Hashable, Any]), dict) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
4319 | | - check(assert_type(df.to_dict(orient="index", index=False), dict[Hashable, Any]), dict) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
| 4314 | + check( |
| 4315 | + assert_type( |
| 4316 | + df.to_dict(orient="records", index=False), list[dict[Hashable, Any]] |
| 4317 | + ), |
| 4318 | + list, |
| 4319 | + ) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
| 4320 | + check( |
| 4321 | + assert_type(df.to_dict(orient="dict", index=False), dict[Hashable, Any]), |
| 4322 | + dict, |
| 4323 | + ) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
| 4324 | + check( |
| 4325 | + assert_type(df.to_dict(orient="series", index=False), dict[Hashable, Any]), |
| 4326 | + dict, |
| 4327 | + ) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
| 4328 | + check( |
| 4329 | + assert_type(df.to_dict(orient="index", index=False), dict[Hashable, Any]), |
| 4330 | + dict, |
| 4331 | + ) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] |
4320 | 4332 |
|
4321 | 4333 |
|
4322 | 4334 | def test_suffix_prefix_index() -> None: |
@@ -4420,7 +4432,9 @@ def test_interpolate_inplace() -> None: |
4420 | 4432 |
|
4421 | 4433 | def test_getitem_generator() -> None: |
4422 | 4434 | # GH 685 |
4423 | | - check(assert_type(DF[(f"col{i+1}" for i in range(2))], pd.DataFrame), pd.DataFrame) |
| 4435 | + check( |
| 4436 | + assert_type(DF[(f"col{i + 1}" for i in range(2))], pd.DataFrame), pd.DataFrame |
| 4437 | + ) |
4424 | 4438 |
|
4425 | 4439 |
|
4426 | 4440 | def test_getitem_dict_keys() -> None: |
@@ -4566,7 +4580,6 @@ def test_hashable_args() -> None: |
4566 | 4580 | test = ["test"] |
4567 | 4581 |
|
4568 | 4582 | with ensure_clean() as path: |
4569 | | - |
4570 | 4583 | df.to_stata(path, version=117, convert_strl=test) |
4571 | 4584 | df.to_stata(path, version=117, convert_strl=["test"]) |
4572 | 4585 |
|
@@ -4691,7 +4704,6 @@ def test_unstack() -> None: |
4691 | 4704 |
|
4692 | 4705 |
|
4693 | 4706 | def test_from_records() -> None: |
4694 | | - |
4695 | 4707 | # test with np.ndarray |
4696 | 4708 | arr = np.array([[1, "a"], [2, "b"]], dtype=object).reshape(2, 2) |
4697 | 4709 | check(assert_type(pd.DataFrame.from_records(arr), pd.DataFrame), pd.DataFrame) |
|
0 commit comments