Skip to content

Commit 2e1126c

Browse files
committed
Issue pandas-dev#5 done: typing improvements for Index
1 parent 51a69e7 commit 2e1126c

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

pandas/core/indexes/base.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
Axis,
5252
AxisInt,
5353
DropKeep,
54+
Dtype,
5455
DtypeObj,
5556
F,
5657
IgnoreRaise,
@@ -1035,7 +1036,7 @@ def view(self, cls=None):
10351036
result._id = self._id
10361037
return result
10371038

1038-
def astype(self, dtype, copy: bool = True):
1039+
def astype(self, dtype: Dtype | None = None, copy: bool = True):
10391040
"""
10401041
Create an Index with values cast to dtypes.
10411042
@@ -1229,7 +1230,7 @@ def _maybe_disallow_fill(self, allow_fill: bool, fill_value, indices) -> bool:
12291230
"""
12301231

12311232
@Appender(_index_shared_docs["repeat"] % _index_doc_kwargs)
1232-
def repeat(self, repeats, axis=None):
1233+
def repeat(self, repeats, axis: AxisInt | None = None):
12331234
repeats = ensure_platform_int(repeats)
12341235
nv.validate_repeat((), {"axis": axis})
12351236
res_values = self._values.repeat(repeats)
@@ -3216,7 +3217,7 @@ def _dti_setop_align_tzs(self, other: Index, setop: str_t) -> tuple[Index, Index
32163217
return self, other
32173218

32183219
@final
3219-
def union(self, other, sort=None):
3220+
def union(self, other, sort: bool | None = None):
32203221
"""
32213222
Form the union of two Index objects.
32223223
@@ -3578,7 +3579,7 @@ def _intersection_via_get_indexer(
35783579
return result
35793580

35803581
@final
3581-
def difference(self, other, sort=None):
3582+
def difference(self, other, sort: bool | None = None):
35823583
"""
35833584
Return a new Index with elements of index not in `other`.
35843585
@@ -3662,7 +3663,9 @@ def _wrap_difference_result(self, other, result):
36623663
# We will override for MultiIndex to handle empty results
36633664
return self._wrap_setop_result(other, result)
36643665

3665-
def symmetric_difference(self, other, result_name=None, sort=None):
3666+
def symmetric_difference(
3667+
self, other, result_name: str | None = None, sort: bool | None = None
3668+
):
36663669
"""
36673670
Compute the symmetric difference of two Index objects.
36683671
@@ -6450,7 +6453,7 @@ def _transform_index(self, func, *, level=None) -> Index:
64506453
items = [func(x) for x in self]
64516454
return Index(items, name=self.name, tupleize_cols=False)
64526455

6453-
def isin(self, values, level=None) -> npt.NDArray[np.bool_]:
6456+
def isin(self, values, level: str | int = None) -> npt.NDArray[np.bool_]:
64546457
"""
64556458
Return a boolean array where the index values are in `values`.
64566459
@@ -6750,7 +6753,9 @@ def get_slice_bound(self, label, side: Literal["left", "right"]) -> int:
67506753
else:
67516754
return slc
67526755

6753-
def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:
6756+
def slice_locs(
6757+
self, start: str | None = None, end: str | None = None, step: int | None = None
6758+
) -> tuple[int, int]:
67546759
"""
67556760
Compute slice locations for input labels.
67566761
@@ -6838,7 +6843,7 @@ def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:
68386843

68396844
return start_slice, end_slice
68406845

6841-
def delete(self, loc) -> Self:
6846+
def delete(self, loc: int | list[int]) -> Self:
68426847
"""
68436848
Make new Index with passed location(-s) deleted.
68446849
@@ -7269,7 +7274,9 @@ def _maybe_disable_logical_methods(self, opname: str_t) -> None:
72697274
make_invalid_op(opname)(self)
72707275

72717276
@Appender(IndexOpsMixin.argmin.__doc__)
7272-
def argmin(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs) -> int:
7277+
def argmin(
7278+
self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs
7279+
) -> int:
72737280
nv.validate_argmin(args, kwargs)
72747281
nv.validate_minmax_axis(axis)
72757282

@@ -7288,7 +7295,9 @@ def argmin(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs
72887295
return super().argmin(skipna=skipna)
72897296

72907297
@Appender(IndexOpsMixin.argmax.__doc__)
7291-
def argmax(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs) -> int:
7298+
def argmax(
7299+
self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs
7300+
) -> int:
72927301
nv.validate_argmax(args, kwargs)
72937302
nv.validate_minmax_axis(axis)
72947303

@@ -7306,7 +7315,7 @@ def argmax(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs
73067315
return -1
73077316
return super().argmax(skipna=skipna)
73087317

7309-
def min(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs):
7318+
def min(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs):
73107319
"""
73117320
Return the minimum value of the Index.
73127321
@@ -7369,7 +7378,7 @@ def min(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs):
73697378

73707379
return nanops.nanmin(self._values, skipna=skipna)
73717380

7372-
def max(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs):
7381+
def max(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs):
73737382
"""
73747383
Return the maximum value of the Index.
73757384

0 commit comments

Comments
 (0)