|
4 | 4 |
|
5 | 5 | import builtins
|
6 | 6 | import textwrap
|
7 |
| -from typing import Any, Callable, Dict, FrozenSet, List, Optional, Union, cast |
| 7 | +from typing import Any, Callable, Dict, FrozenSet, List, Optional, TypeVar, Union, cast |
8 | 8 |
|
9 | 9 | import numpy as np
|
10 | 10 |
|
|
43 | 43 | duplicated="IndexOpsMixin",
|
44 | 44 | )
|
45 | 45 |
|
| 46 | +_T = TypeVar("_T", bound="IndexOpsMixin") |
| 47 | + |
46 | 48 |
|
47 | 49 | class PandasObject(DirNamesMixin):
|
48 | 50 | """
|
@@ -604,7 +606,7 @@ def _values(self) -> Union[ExtensionArray, np.ndarray]:
|
604 | 606 | # must be defined here as a property for mypy
|
605 | 607 | raise AbstractMethodError(self)
|
606 | 608 |
|
607 |
| - def transpose(self, *args, **kwargs): |
| 609 | + def transpose(self: _T, *args, **kwargs) -> _T: |
608 | 610 | """
|
609 | 611 | Return the transpose, which is by definition self.
|
610 | 612 |
|
@@ -851,10 +853,10 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default, **kwargs):
|
851 | 853 | return result
|
852 | 854 |
|
853 | 855 | @property
|
854 |
| - def empty(self): |
| 856 | + def empty(self) -> bool: |
855 | 857 | return not self.size
|
856 | 858 |
|
857 |
| - def max(self, axis=None, skipna=True, *args, **kwargs): |
| 859 | + def max(self, axis=None, skipna: bool = True, *args, **kwargs): |
858 | 860 | """
|
859 | 861 | Return the maximum value of the Index.
|
860 | 862 |
|
@@ -899,7 +901,7 @@ def max(self, axis=None, skipna=True, *args, **kwargs):
|
899 | 901 | return nanops.nanmax(self._values, skipna=skipna)
|
900 | 902 |
|
901 | 903 | @doc(op="max", oppose="min", value="largest")
|
902 |
| - def argmax(self, axis=None, skipna=True, *args, **kwargs): |
| 904 | + def argmax(self, axis=None, skipna: bool = True, *args, **kwargs) -> int: |
903 | 905 | """
|
904 | 906 | Return int position of the {value} value in the Series.
|
905 | 907 |
|
@@ -954,7 +956,7 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):
|
954 | 956 | nv.validate_argmax_with_skipna(skipna, args, kwargs)
|
955 | 957 | return nanops.nanargmax(self._values, skipna=skipna)
|
956 | 958 |
|
957 |
| - def min(self, axis=None, skipna=True, *args, **kwargs): |
| 959 | + def min(self, axis=None, skipna: bool = True, *args, **kwargs): |
958 | 960 | """
|
959 | 961 | Return the minimum value of the Index.
|
960 | 962 |
|
@@ -999,7 +1001,7 @@ def min(self, axis=None, skipna=True, *args, **kwargs):
|
999 | 1001 | return nanops.nanmin(self._values, skipna=skipna)
|
1000 | 1002 |
|
1001 | 1003 | @doc(argmax, op="min", oppose="max", value="smallest")
|
1002 |
| - def argmin(self, axis=None, skipna=True, *args, **kwargs): |
| 1004 | + def argmin(self, axis=None, skipna=True, *args, **kwargs) -> int: |
1003 | 1005 | nv.validate_minmax_axis(axis)
|
1004 | 1006 | nv.validate_argmax_with_skipna(skipna, args, kwargs)
|
1005 | 1007 | return nanops.nanargmin(self._values, skipna=skipna)
|
@@ -1054,6 +1056,9 @@ def hasnans(self):
|
1054 | 1056 | """
|
1055 | 1057 | return bool(isna(self).any())
|
1056 | 1058 |
|
| 1059 | + def isna(self): |
| 1060 | + return isna(self._values) |
| 1061 | + |
1057 | 1062 | def _reduce(
|
1058 | 1063 | self,
|
1059 | 1064 | op,
|
@@ -1161,7 +1166,12 @@ def map_f(values, f):
|
1161 | 1166 | return new_values
|
1162 | 1167 |
|
1163 | 1168 | def value_counts(
|
1164 |
| - self, normalize=False, sort=True, ascending=False, bins=None, dropna=True |
| 1169 | + self, |
| 1170 | + normalize: bool = False, |
| 1171 | + sort: bool = True, |
| 1172 | + ascending: bool = False, |
| 1173 | + bins=None, |
| 1174 | + dropna: bool = True, |
1165 | 1175 | ):
|
1166 | 1176 | """
|
1167 | 1177 | Return a Series containing counts of unique values.
|
@@ -1500,20 +1510,9 @@ def searchsorted(self, value, side="left", sorter=None) -> np.ndarray:
|
1500 | 1510 | return algorithms.searchsorted(self._values, value, side=side, sorter=sorter)
|
1501 | 1511 |
|
1502 | 1512 | def drop_duplicates(self, keep="first"):
|
1503 |
| - if isinstance(self, ABCIndexClass): |
1504 |
| - if self.is_unique: |
1505 |
| - return self._shallow_copy() |
1506 |
| - |
1507 | 1513 | duplicated = self.duplicated(keep=keep)
|
1508 | 1514 | result = self[np.logical_not(duplicated)]
|
1509 | 1515 | return result
|
1510 | 1516 |
|
1511 | 1517 | def duplicated(self, keep="first"):
|
1512 |
| - if isinstance(self, ABCIndexClass): |
1513 |
| - if self.is_unique: |
1514 |
| - return np.zeros(len(self), dtype=bool) |
1515 |
| - return duplicated(self, keep=keep) |
1516 |
| - else: |
1517 |
| - return self._constructor( |
1518 |
| - duplicated(self, keep=keep), index=self.index |
1519 |
| - ).__finalize__(self, method="duplicated") |
| 1518 | + return duplicated(self._values, keep=keep) |
0 commit comments