Skip to content

Commit a47d0df

Browse files
committed
TYP: Use Self for type checking
1 parent 2070bb8 commit a47d0df

File tree

7 files changed

+214
-224
lines changed

7 files changed

+214
-224
lines changed

pandas/_typing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
tzinfo,
77
)
88
from os import PathLike
9+
import sys
910
from typing import (
1011
TYPE_CHECKING,
1112
Any,
@@ -83,8 +84,13 @@
8384
# Name "npt._ArrayLikeInt_co" is not defined [name-defined]
8485
NumpySorter = Optional[npt._ArrayLikeInt_co] # type: ignore[name-defined]
8586

87+
if sys.version_info >= (3, 11):
88+
from typing import Self
89+
else:
90+
from typing_extensions import Self # pyright: reportUnusedImport = false
8691
else:
8792
npt: Any = None
93+
Self: Any = None
8894

8995
HashableT = TypeVar("HashableT", bound=Hashable)
9096

pandas/core/frame.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@
7878
Level,
7979
MergeHow,
8080
NaPosition,
81+
NDFrameT,
8182
PythonFuncType,
8283
QuantileInterpolation,
8384
ReadBuffer,
8485
Renamer,
8586
Scalar,
87+
Self,
8688
SortKind,
8789
StorageOptions,
8890
Suffixes,
@@ -4951,7 +4953,7 @@ def _reindex_multi(
49514953
@doc(NDFrame.align, **_shared_doc_kwargs)
49524954
def align(
49534955
self,
4954-
other: DataFrame,
4956+
other: NDFrameT,
49554957
join: AlignJoin = "outer",
49564958
axis: Axis | None = None,
49574959
level: Level = None,
@@ -4961,7 +4963,7 @@ def align(
49614963
limit: int | None = None,
49624964
fill_axis: Axis = 0,
49634965
broadcast_axis: Axis | None = None,
4964-
) -> DataFrame:
4966+
) -> tuple[Self, NDFrameT]:
49654967
return super().align(
49664968
other,
49674969
join=join,

0 commit comments

Comments
 (0)