diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 64c5b735fdc8d..962e7cc86a98b 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -254,13 +254,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.util.hash_pandas_object \ pandas_object \ pandas.api.interchange.from_dataframe \ - pandas.Index.drop \ - pandas.Index.identical \ - pandas.Index.insert \ - pandas.Index.is_ \ - pandas.Index.take \ - pandas.Index.putmask \ - pandas.Index.unique \ pandas.Index.fillna \ pandas.Index.dropna \ pandas.Index.astype \ diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 174c6625fb779..aa8bfb667f5be 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -799,6 +799,15 @@ def is_(self, other) -> bool: See Also -------- Index.identical : Works like ``Index.is_`` but also checks metadata. + + Examples + -------- + >>> idx1 = pd.Index(['1', '2', '3']) + >>> idx1.is_(idx1.view()) + True + + >>> idx1.is_(idx1.copy()) + False """ if self is other: return True @@ -1089,6 +1098,12 @@ def astype(self, dtype, copy: bool = True): -------- numpy.ndarray.take: Return an array formed from the elements of a at the given indices. + + Examples + -------- + >>> idx = pd.Index(['a', 'b', 'c']) + >>> idx.take([2, 2, 1, 2]) + Index(['c', 'c', 'b', 'c'], dtype='object') """ @Appender(_index_shared_docs["take"] % _index_doc_kwargs) @@ -2966,6 +2981,12 @@ def unique(self, level: Hashable | None = None) -> Self: -------- unique : Numpy array of unique values in that column. Series.unique : Return unique values of Series object. + + Examples + -------- + >>> idx = pd.Index([1, 1, 2, 3, 3]) + >>> idx.unique() + Index([1, 2, 3], dtype='int64') """ if level is not None: self._validate_index_level(level) @@ -5345,6 +5366,13 @@ def putmask(self, mask, value) -> Index: -------- numpy.ndarray.putmask : Changes elements of an array based on conditional and input values. + + Examples + -------- + >>> idx1 = pd.Index([1, 2, 3]) + >>> idx2 = pd.Index([5, 6, 7]) + >>> idx1.putmask([True, False, False], idx2) + Index([5, 2, 3], dtype='int64') """ mask, noop = validate_putmask(self._values, mask) if noop: @@ -5474,6 +5502,18 @@ def identical(self, other) -> bool: bool If two Index objects have equal elements and same type True, otherwise False. + + Examples + -------- + >>> idx1 = pd.Index(['1', '2', '3']) + >>> idx2 = pd.Index(['1', '2', '3']) + >>> idx2.identical(idx1) + True + + >>> idx1 = pd.Index(['1', '2', '3'], name="A") + >>> idx2 = pd.Index(['1', '2', '3'], name="B") + >>> idx2.identical(idx1) + False """ return ( self.equals(other) @@ -6694,6 +6734,12 @@ def insert(self, loc: int, item) -> Index: Returns ------- Index + + Examples + -------- + >>> idx = pd.Index(['a', 'b', 'c']) + >>> idx.insert(1, 'x') + Index(['a', 'x', 'b', 'c'], dtype='object') """ item = lib.item_from_zerodim(item) if is_valid_na_for_dtype(item, self.dtype) and self.dtype != object: @@ -6755,6 +6801,12 @@ def drop( ------ KeyError If not all of the labels are found in the selected axis + + Examples + -------- + >>> idx = pd.Index(['a', 'b', 'c']) + >>> idx.drop(['a']) + Index(['b', 'c'], dtype='object') """ if not isinstance(labels, Index): # avoid materializing e.g. RangeIndex