diff --git a/ci/code_checks.sh b/ci/code_checks.sh index eceb076021a7e..6fcb8222f0359 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -117,7 +117,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.errors.DataError \ pandas.errors.IncompatibilityWarning \ pandas.errors.InvalidComparison \ - pandas.errors.InvalidVersion \ pandas.errors.IntCastingNaNError \ pandas.errors.LossySetitemError \ pandas.errors.MergeError \ @@ -165,7 +164,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Period.asfreq \ pandas.Period.now \ pandas.arrays.PeriodArray \ - pandas.NA \ pandas.CategoricalDtype.categories \ pandas.CategoricalDtype.ordered \ pandas.Categorical.dtype \ @@ -241,13 +239,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.util.hash_pandas_object \ pandas_object \ pandas.api.interchange.from_dataframe \ - pandas.Index.fillna \ - pandas.Index.dropna \ - pandas.Index.astype \ - pandas.Index.map \ - pandas.Index.to_list \ - pandas.Index.append \ - pandas.Index.join \ pandas.Index.asof_locs \ pandas.Index.get_slice_bound \ pandas.RangeIndex \ diff --git a/pandas/_libs/missing.pyx b/pandas/_libs/missing.pyx index 75955180447c4..e3e7d8daa03e1 100644 --- a/pandas/_libs/missing.pyx +++ b/pandas/_libs/missing.pyx @@ -377,6 +377,26 @@ class NAType(C_NAType): The NA singleton is a missing value indicator defined by pandas. It is used in certain new extension dtypes (currently the "string" dtype). + + Examples + -------- + >>> pd.NA + + + >>> True | pd.NA + True + + >>> True & pd.NA + + + >>> pd.NA != pd.NA + + + >>> pd.NA == pd.NA + + + >>> True | pd.NA + True """ _instance = None diff --git a/pandas/core/base.py b/pandas/core/base.py index 0d99118d25e96..f66abaa17d8a7 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -765,9 +765,20 @@ def tolist(self): Examples -------- + For Series + >>> s = pd.Series([1, 2, 3]) >>> s.to_list() [1, 2, 3] + + For Index: + + >>> idx = pd.Index([1, 2, 3]) + >>> idx + Index([1, 2, 3], dtype='int64') + + >>> idx.to_list() + [1, 2, 3] """ return self._values.tolist() diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 4c67534fcf1c2..c9a5fb5c809ed 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1056,6 +1056,14 @@ def astype(self, dtype, copy: bool = True): ------- Index Index with values cast to specified dtype. + + Examples + -------- + >>> idx = pd.Index([1, 2, 3]) + >>> idx + Index([1, 2, 3], dtype='int64') + >>> idx.astype('float') + Index([1.0, 2.0, 3.0], dtype='float64') """ if dtype is not None: dtype = pandas_dtype(dtype) @@ -2939,6 +2947,12 @@ def fillna(self, value=None, downcast=None): -------- DataFrame.fillna : Fill NaN values of a DataFrame. Series.fillna : Fill NaN Values of a Series. + + Examples + -------- + >>> idx = pd.Index([np.nan, np.nan, 3]) + >>> idx.fillna(0) + Index([0.0, 0.0, 3.0], dtype='float64') """ if not is_scalar(value): raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}") @@ -2969,6 +2983,12 @@ def dropna(self, how: AnyAll = "any") -> Self: Returns ------- Index + + Examples + -------- + >>> idx = pd.Index([1, np.nan, 3]) + >>> idx.dropna() + Index([1.0, 3.0], dtype='float64') """ if how not in ("any", "all"): raise ValueError(f"invalid how option: {how}") @@ -4535,6 +4555,13 @@ def join( Returns ------- join_index, (left_indexer, right_indexer) + + Examples + -------- + >>> idx1 = pd.Index([1, 2, 3]) + >>> idx2 = pd.Index([4, 5, 6]) + >>> idx1.join(idx2, how='outer') + Index([1, 2, 3, 4, 5, 6], dtype='int64') """ other = ensure_index(other) @@ -5359,6 +5386,12 @@ def append(self, other: Index | Sequence[Index]) -> Index: Returns ------- Index + + Examples + -------- + >>> idx = pd.Index([1, 2, 3]) + >>> idx.append(pd.Index([4])) + Index([1, 2, 3, 4], dtype='int64') """ to_concat = [self] @@ -6295,6 +6328,22 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None): The output of the mapping function applied to the index. If the function returns a tuple with more than one element a MultiIndex will be returned. + + Examples + -------- + >>> idx = pd.Index([1, 2, 3]) + >>> idx.map({1: 'a', 2: 'b', 3: 'c'}) + Index(['a', 'b', 'c'], dtype='object') + + Using `map` with a function: + + >>> idx = pd.Index([1, 2, 3]) + >>> idx.map('I am a {}'.format) + Index(['I am a 1', 'I am a 2', 'I am a 3'], dtype='object') + + >>> idx = pd.Index(['a', 'b', 'c']) + >>> idx.map(lambda x: x.upper()) + Index(['A', 'B', 'C'], dtype='object') """ from pandas.core.indexes.multi import MultiIndex diff --git a/pandas/util/version/__init__.py b/pandas/util/version/__init__.py index ea0047f6cfd77..5d4937451c49c 100644 --- a/pandas/util/version/__init__.py +++ b/pandas/util/version/__init__.py @@ -129,6 +129,12 @@ def parse(version: str) -> LegacyVersion | Version: class InvalidVersion(ValueError): """ An invalid version was found, users should refer to PEP 440. + + Examples + -------- + >>> pd.util.version.Version('1.') + Traceback (most recent call last): + InvalidVersion: Invalid version: '1.' """