Skip to content

Commit

Permalink
Issue pandas-dev#5 done: typing improvements for Index
Browse files Browse the repository at this point in the history
  • Loading branch information
ghraciella committed Jul 28, 2023
1 parent 51a69e7 commit 2e1126c
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Axis,
AxisInt,
DropKeep,
Dtype,
DtypeObj,
F,
IgnoreRaise,
Expand Down Expand Up @@ -1035,7 +1036,7 @@ def view(self, cls=None):
result._id = self._id
return result

def astype(self, dtype, copy: bool = True):
def astype(self, dtype: Dtype | None = None, copy: bool = True):
"""
Create an Index with values cast to dtypes.
Expand Down Expand Up @@ -1229,7 +1230,7 @@ def _maybe_disallow_fill(self, allow_fill: bool, fill_value, indices) -> bool:
"""

@Appender(_index_shared_docs["repeat"] % _index_doc_kwargs)
def repeat(self, repeats, axis=None):
def repeat(self, repeats, axis: AxisInt | None = None):
repeats = ensure_platform_int(repeats)
nv.validate_repeat((), {"axis": axis})
res_values = self._values.repeat(repeats)
Expand Down Expand Up @@ -3216,7 +3217,7 @@ def _dti_setop_align_tzs(self, other: Index, setop: str_t) -> tuple[Index, Index
return self, other

@final
def union(self, other, sort=None):
def union(self, other, sort: bool | None = None):
"""
Form the union of two Index objects.
Expand Down Expand Up @@ -3578,7 +3579,7 @@ def _intersection_via_get_indexer(
return result

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

def symmetric_difference(self, other, result_name=None, sort=None):
def symmetric_difference(
self, other, result_name: str | None = None, sort: bool | None = None
):
"""
Compute the symmetric difference of two Index objects.
Expand Down Expand Up @@ -6450,7 +6453,7 @@ def _transform_index(self, func, *, level=None) -> Index:
items = [func(x) for x in self]
return Index(items, name=self.name, tupleize_cols=False)

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

def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:
def slice_locs(
self, start: str | None = None, end: str | None = None, step: int | None = None
) -> tuple[int, int]:
"""
Compute slice locations for input labels.
Expand Down Expand Up @@ -6838,7 +6843,7 @@ def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:

return start_slice, end_slice

def delete(self, loc) -> Self:
def delete(self, loc: int | list[int]) -> Self:
"""
Make new Index with passed location(-s) deleted.
Expand Down Expand Up @@ -7269,7 +7274,9 @@ def _maybe_disable_logical_methods(self, opname: str_t) -> None:
make_invalid_op(opname)(self)

@Appender(IndexOpsMixin.argmin.__doc__)
def argmin(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs) -> int:
def argmin(
self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs
) -> int:
nv.validate_argmin(args, kwargs)
nv.validate_minmax_axis(axis)

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

@Appender(IndexOpsMixin.argmax.__doc__)
def argmax(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs) -> int:
def argmax(
self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs
) -> int:
nv.validate_argmax(args, kwargs)
nv.validate_minmax_axis(axis)

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

def min(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs):
def min(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs):
"""
Return the minimum value of the Index.
Expand Down Expand Up @@ -7369,7 +7378,7 @@ def min(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs):

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

def max(self, axis: AxisInt|None = None, skipna: bool = True, *args, **kwargs):
def max(self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs):
"""
Return the maximum value of the Index.
Expand Down

0 comments on commit 2e1126c

Please sign in to comment.