Skip to content

Commit 6c50f70

Browse files
authored
DOC Fix EX01 in docstrings - added examples (#52158)
* added hasnas examples * added example for Series.to_list * changed test
1 parent b63d35d commit 6c50f70

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

ci/code_checks.sh

-3
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8686
MSG='Partially validate docstrings (EX01)' ; echo $MSG
8787
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
8888
pandas.Series.index \
89-
pandas.Series.hasnans \
90-
pandas.Series.to_list \
9189
pandas.Series.__iter__ \
9290
pandas.Series.keys \
9391
pandas.Series.item \
@@ -309,7 +307,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
309307
pandas_object \
310308
pandas.api.interchange.from_dataframe \
311309
pandas.Index.values \
312-
pandas.Index.hasnans \
313310
pandas.Index.dtype \
314311
pandas.Index.inferred_type \
315312
pandas.Index.shape \

pandas/core/base.py

+18
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,12 @@ def tolist(self):
801801
--------
802802
numpy.ndarray.tolist : Return the array as an a.ndim-levels deep
803803
nested list of Python scalars.
804+
805+
Examples
806+
--------
807+
>>> s = pd.Series([1, 2, 3])
808+
>>> s.to_list()
809+
[1, 2, 3]
804810
"""
805811
return self._values.tolist()
806812

@@ -835,6 +841,18 @@ def hasnans(self) -> bool:
835841
Returns
836842
-------
837843
bool
844+
845+
Examples
846+
--------
847+
>>> s = pd.Series([1, 2, 3, None])
848+
>>> s
849+
0 1.0
850+
1 2.0
851+
2 3.0
852+
3 NaN
853+
dtype: float64
854+
>>> s.hasnans
855+
True
838856
"""
839857
# error: Item "bool" of "Union[bool, ndarray[Any, dtype[bool_]], NDFrame]"
840858
# has no attribute "any"

pandas/core/indexes/base.py

+11
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,17 @@ def hasnans(self) -> bool:
27142714
Returns
27152715
-------
27162716
bool
2717+
2718+
Examples
2719+
--------
2720+
>>> s = pd.Series([1, 2, 3], index=['a', 'b', None])
2721+
>>> s
2722+
a 1
2723+
b 2
2724+
None 3
2725+
dtype: int64
2726+
>>> s.index.hasnans
2727+
True
27172728
"""
27182729
if self._can_hold_na:
27192730
return bool(self._isnan.any())

pandas/tests/series/test_missing.py

-1
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,3 @@ def test_hasnans_uncached_for_series():
9999
assert not hasattr(ser, "_cache")
100100
ser.iloc[-1] = np.nan
101101
assert ser.hasnans is True
102-
assert Series.hasnans.__doc__ == Index.hasnans.__doc__

0 commit comments

Comments
 (0)