diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 55618590071b5..d450630227e2a 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -85,8 +85,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.__iter__ \ - pandas.Series.keys \ pandas.Series.item \ pandas.Series.pipe \ pandas.Series.mode \ @@ -533,8 +531,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.api.extensions.ExtensionArray.shape \ pandas.api.extensions.ExtensionArray.tolist \ pandas.DataFrame.columns \ - pandas.DataFrame.__iter__ \ - pandas.DataFrame.keys \ pandas.DataFrame.iterrows \ pandas.DataFrame.pipe \ pandas.DataFrame.backfill \ diff --git a/pandas/core/base.py b/pandas/core/base.py index 5bc0fc3e1af63..b281dace12fcb 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -736,6 +736,15 @@ def __iter__(self) -> Iterator: Returns ------- iterator + + Examples + -------- + >>> s = pd.Series([1, 2, 3]) + >>> for x in s: + ... print(x) + 1 + 2 + 3 """ # We are explicitly making element iterators. if not isinstance(self._values, np.ndarray): diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 34dbb7619608d..e01d3c44172c2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1900,6 +1900,14 @@ def __iter__(self) -> Iterator: ------- iterator Info axis as iterator. + + Examples + -------- + >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) + >>> for x in df: + ... print(x) + A + B """ return iter(self._info_axis) @@ -1914,6 +1922,18 @@ def keys(self) -> Index: ------- Index Info axis. + + Examples + -------- + >>> d = pd.DataFrame(data={'A': [1, 2, 3], 'B': [0, 4, 8]}, + ... index=['a', 'b', 'c']) + >>> d + A B + a 1 0 + b 2 4 + c 3 8 + >>> d.keys() + Index(['A', 'B'], dtype='object') """ return self._info_axis diff --git a/pandas/core/series.py b/pandas/core/series.py index 9693981cc5422..53b56fc8686bf 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1822,6 +1822,12 @@ def keys(self) -> Index: ------- Index Index of the Series. + + Examples + -------- + >>> s = pd.Series([1, 2, 3], index=[0, 1, 2]) + >>> s.keys() + Index([0, 1, 2], dtype='int64') """ return self.index