Skip to content

Commit 3620d66

Browse files
committed
TYP: Use Self for type checking (remaining locations/)
1 parent 3238381 commit 3620d66

File tree

7 files changed

+8
-65
lines changed

7 files changed

+8
-65
lines changed

.startup.ipy

-48
This file was deleted.

pandas/core/base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Hashable,
1313
Iterator,
1414
Literal,
15-
TypeVar,
1615
cast,
1716
final,
1817
overload,
@@ -29,6 +28,7 @@
2928
DtypeObj,
3029
IndexLabel,
3130
NDFrameT,
31+
Self,
3232
Shape,
3333
npt,
3434
)
@@ -91,8 +91,6 @@
9191
"duplicated": "IndexOpsMixin",
9292
}
9393

94-
_T = TypeVar("_T", bound="IndexOpsMixin")
95-
9694

9795
class PandasObject(DirNamesMixin):
9896
"""
@@ -285,7 +283,7 @@ def _values(self) -> ExtensionArray | np.ndarray:
285283
raise AbstractMethodError(self)
286284

287285
@final
288-
def transpose(self: _T, *args, **kwargs) -> _T:
286+
def transpose(self, *args, **kwargs) -> Self:
289287
"""
290288
Return the transpose, which is by definition self.
291289

pandas/core/dtypes/base.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
if TYPE_CHECKING:
2727
from pandas._typing import (
2828
DtypeObj,
29+
Self,
2930
Shape,
3031
npt,
3132
type_t,
@@ -228,9 +229,7 @@ def empty(self, shape: Shape) -> type_t[ExtensionArray]:
228229
return cls._empty(shape, dtype=self)
229230

230231
@classmethod
231-
def construct_from_string(
232-
cls: type_t[ExtensionDtypeT], string: str
233-
) -> ExtensionDtypeT:
232+
def construct_from_string(cls, string: str) -> Self:
234233
r"""
235234
Construct this type from a string.
236235

pandas/core/indexing.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
TYPE_CHECKING,
77
Hashable,
88
Sequence,
9-
TypeVar,
109
cast,
1110
final,
1211
)
@@ -78,15 +77,14 @@
7877
from pandas._typing import (
7978
Axis,
8079
AxisInt,
80+
Self,
8181
)
8282

8383
from pandas import (
8484
DataFrame,
8585
Series,
8686
)
8787

88-
_LocationIndexerT = TypeVar("_LocationIndexerT", bound="_LocationIndexer")
89-
9088
# "null slice"
9189
_NS = slice(None, None)
9290
_one_ellipsis_message = "indexer may only contain one '...' entry"
@@ -669,9 +667,7 @@ class _LocationIndexer(NDFrameIndexerBase):
669667
_takeable: bool
670668

671669
@final
672-
def __call__(
673-
self: _LocationIndexerT, axis: Axis | None = None
674-
) -> _LocationIndexerT:
670+
def __call__(self, axis: Axis | None = None) -> Self:
675671
# we need to return a copy of ourselves
676672
new_self = type(self)(self.name, self.obj)
677673

pandas/core/internals/array_manager.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
ArrayLike,
9292
AxisInt,
9393
DtypeObj,
94-
Self,
9594
QuantileInterpolation,
95+
Self,
9696
npt,
9797
)
9898

@@ -637,7 +637,6 @@ def take(
637637
indexer: npt.NDArray[np.intp],
638638
axis: AxisInt = 1,
639639
verify: bool = True,
640-
convert_indices: bool = True,
641640
) -> Self:
642641
"""
643642
Take items along any axis.

pandas/core/internals/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Shape,
3535
)
3636

37+
3738
class DataManager(PandasObject):
3839
# TODO share more methods/attributes
3940

pandas/core/internals/managers.py

-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
Self,
8787
Shape,
8888
npt,
89-
type_t,
9089
)
9190

9291

@@ -929,7 +928,6 @@ def take(
929928
indexer: npt.NDArray[np.intp],
930929
axis: AxisInt = 1,
931930
verify: bool = True,
932-
convert_indices: bool = True,
933931
) -> Self:
934932
"""
935933
Take items along any axis.

0 commit comments

Comments
 (0)