diff --git a/ci/code_checks.sh b/ci/code_checks.sh index b3ca4e213aea9..45df480779ee7 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -86,8 +86,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then MSG='Partially validate docstrings (EX01)' ; echo $MSG $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \ pandas.Series.index \ - pandas.Series.hasnans \ - pandas.Series.to_list \ pandas.Series.__iter__ \ pandas.Series.keys \ pandas.Series.item \ @@ -309,7 +307,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas_object \ pandas.api.interchange.from_dataframe \ pandas.Index.values \ - pandas.Index.hasnans \ pandas.Index.dtype \ pandas.Index.inferred_type \ pandas.Index.shape \ diff --git a/pandas/core/base.py b/pandas/core/base.py index 96209ba97c0aa..d085807981fa8 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -801,6 +801,12 @@ def tolist(self): -------- numpy.ndarray.tolist : Return the array as an a.ndim-levels deep nested list of Python scalars. + + Examples + -------- + >>> s = pd.Series([1, 2, 3]) + >>> s.to_list() + [1, 2, 3] """ return self._values.tolist() @@ -835,6 +841,18 @@ def hasnans(self) -> bool: Returns ------- bool + + Examples + -------- + >>> s = pd.Series([1, 2, 3, None]) + >>> s + 0 1.0 + 1 2.0 + 2 3.0 + 3 NaN + dtype: float64 + >>> s.hasnans + True """ # error: Item "bool" of "Union[bool, ndarray[Any, dtype[bool_]], NDFrame]" # has no attribute "any" diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 273b42d725a91..c93eb0fe3def6 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2714,6 +2714,17 @@ def hasnans(self) -> bool: Returns ------- bool + + Examples + -------- + >>> s = pd.Series([1, 2, 3], index=['a', 'b', None]) + >>> s + a 1 + b 2 + None 3 + dtype: int64 + >>> s.index.hasnans + True """ if self._can_hold_na: return bool(self._isnan.any()) diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 017721b8a4ee0..c7d80a705b2e4 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -99,4 +99,3 @@ def test_hasnans_uncached_for_series(): assert not hasattr(ser, "_cache") ser.iloc[-1] = np.nan assert ser.hasnans is True - assert Series.hasnans.__doc__ == Index.hasnans.__doc__