Skip to content

Commit

Permalink
replace some hints with literals, move slice_type to _typing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyKolomiets committed Jul 19, 2024
1 parent c084364 commit 36c3495
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
2 changes: 2 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,5 @@ def closed(self) -> bool:

# maintaine the sub-type of any hashable sequence
SequenceT = TypeVar("SequenceT", bound=Sequence[Hashable])

SliceType = Optional[Hashable]
38 changes: 12 additions & 26 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
ClassVar,
Literal,
NoReturn,
Optional,
Union,
cast,
final,
overload,
Expand Down Expand Up @@ -47,6 +45,7 @@
ArrayLike,
Axes,
Axis,
AxisInt,
DropKeep,
Dtype,
DtypeObj,
Expand All @@ -60,6 +59,7 @@
ReindexMethod,
Self,
Shape,
SliceType,
npt,
)
from pandas.compat.numpy import function as nv
Expand Down Expand Up @@ -158,8 +158,6 @@
ExtensionArray,
TimedeltaArray,
)
from pandas.core.arrays.floating import FloatingDtype
from pandas.core.arrays.integer import IntegerDtype
from pandas.core.arrays.string_ import (
StringArray,
StringDtype,
Expand Down Expand Up @@ -317,20 +315,6 @@ def _new_Index(cls, d):
return cls.__new__(cls, **d)


slice_type = Optional[
Union[
str,
IntegerDtype,
FloatingDtype,
DatetimeTZDtype,
CategoricalDtype,
PeriodDtype,
IntervalDtype,
abc.Hashable,
]
]


class Index(IndexOpsMixin, PandasObject):
"""
Immutable sequence used for indexing and alignment.
Expand Down Expand Up @@ -6413,7 +6397,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: np.str_ | int | None = None) -> npt.NDArray[np.bool_]:
def isin(self, values, level: str_t | int | None = None) -> npt.NDArray[np.bool_]:
"""
Return a boolean array where the index values are in `values`.
Expand Down Expand Up @@ -6713,8 +6697,8 @@ def get_slice_bound(self, label, side: Literal["left", "right"]) -> int:

def slice_locs(
self,
start: slice_type = None,
end: slice_type = None,
start: SliceType = None,
end: SliceType = None,
step: int | None = None,
) -> tuple[int, int]:
"""
Expand Down Expand Up @@ -6810,7 +6794,9 @@ def slice_locs(

return start_slice, end_slice

def delete(self, loc: int | np.integer | list[int] | npt.NDArray[np.int_]) -> Self:
def delete(
self, loc: int | np.integer | list[int] | npt.NDArray[np.integer]
) -> Self:
"""
Make new Index with passed location(-s) deleted.
Expand Down Expand Up @@ -7257,7 +7243,7 @@ def _maybe_disable_logical_methods(self, opname: str_t) -> None:

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

@Appender(IndexOpsMixin.argmax.__doc__)
def argmax(
self, axis: int | None = None, skipna: bool = True, *args, **kwargs
self, axis: AxisInt | None = None, skipna: bool = True, *args, **kwargs
) -> int:
nv.validate_argmax(args, kwargs)
nv.validate_minmax_axis(axis)
Expand All @@ -7284,7 +7270,7 @@ def argmax(
raise ValueError("Encountered all NA values")
return super().argmax(skipna=skipna)

def min(self, axis: int | 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 @@ -7347,7 +7333,7 @@ def min(self, axis: int | None = None, skipna: bool = True, *args, **kwargs):

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

def max(self, axis: int | 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 36c3495

Please sign in to comment.