Skip to content

DOC Fix EX01 in docstrings - added examples #52158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
18 changes: 18 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__