Skip to content

Commit cb9d034

Browse files
DeaMariaLeonYi Wei
authored and
Yi Wei
committed
DOC: Fix EX01 issues in docstrings (pandas-dev#52966)
* DOC added examples * DOC added examples * DOC Removed lines from code_check * DOC examples __iter__ not needed?
1 parent 72ce1d3 commit cb9d034

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8585

8686
MSG='Partially validate docstrings (EX01)' ; echo $MSG
8787
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
88-
pandas.Series.__iter__ \
89-
pandas.Series.keys \
9088
pandas.Series.item \
9189
pandas.Series.pipe \
9290
pandas.Series.mode \
@@ -533,8 +531,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
533531
pandas.api.extensions.ExtensionArray.shape \
534532
pandas.api.extensions.ExtensionArray.tolist \
535533
pandas.DataFrame.columns \
536-
pandas.DataFrame.__iter__ \
537-
pandas.DataFrame.keys \
538534
pandas.DataFrame.iterrows \
539535
pandas.DataFrame.pipe \
540536
pandas.DataFrame.backfill \

pandas/core/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ def __iter__(self) -> Iterator:
736736
Returns
737737
-------
738738
iterator
739+
740+
Examples
741+
--------
742+
>>> s = pd.Series([1, 2, 3])
743+
>>> for x in s:
744+
... print(x)
745+
1
746+
2
747+
3
739748
"""
740749
# We are explicitly making element iterators.
741750
if not isinstance(self._values, np.ndarray):

pandas/core/generic.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,14 @@ def __iter__(self) -> Iterator:
19001900
-------
19011901
iterator
19021902
Info axis as iterator.
1903+
1904+
Examples
1905+
--------
1906+
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
1907+
>>> for x in df:
1908+
... print(x)
1909+
A
1910+
B
19031911
"""
19041912
return iter(self._info_axis)
19051913

@@ -1914,6 +1922,18 @@ def keys(self) -> Index:
19141922
-------
19151923
Index
19161924
Info axis.
1925+
1926+
Examples
1927+
--------
1928+
>>> d = pd.DataFrame(data={'A': [1, 2, 3], 'B': [0, 4, 8]},
1929+
... index=['a', 'b', 'c'])
1930+
>>> d
1931+
A B
1932+
a 1 0
1933+
b 2 4
1934+
c 3 8
1935+
>>> d.keys()
1936+
Index(['A', 'B'], dtype='object')
19171937
"""
19181938
return self._info_axis
19191939

pandas/core/series.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,12 @@ def keys(self) -> Index:
18221822
-------
18231823
Index
18241824
Index of the Series.
1825+
1826+
Examples
1827+
--------
1828+
>>> s = pd.Series([1, 2, 3], index=[0, 1, 2])
1829+
>>> s.keys()
1830+
Index([0, 1, 2], dtype='int64')
18251831
"""
18261832
return self.index
18271833

0 commit comments

Comments
 (0)