From d26ccf5ab0c8bd4ee67b87eddb438fcd8cba3234 Mon Sep 17 00:00:00 2001 From: Dea Leon Date: Wed, 26 Apr 2023 17:27:31 +0200 Subject: [PATCH 1/4] DOC added examples --- pandas/core/base.py | 9 +++++++++ pandas/core/generic.py | 20 ++++++++++++++++++++ pandas/core/series.py | 6 ++++++ 3 files changed, 35 insertions(+) diff --git a/pandas/core/base.py b/pandas/core/base.py index f907089f77132..e839b68ae3098 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.__iter__(): + ... 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 9cbb652b33b46..dc577dcb14764 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1897,6 +1897,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.__iter__(): + ... print(x) + A + B """ return iter(self._info_axis) @@ -1911,6 +1919,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 43ebdc2f9dff0..2cc7727947ecc 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1823,6 +1823,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 From f8edd0b1658b83f528d59b46b5d6c763d62548ea Mon Sep 17 00:00:00 2001 From: Dea Leon Date: Wed, 26 Apr 2023 17:28:46 +0200 Subject: [PATCH 2/4] DOC added examples --- ci/code_checks.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index c046d55d80b49..58e16d5ab6bb5 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -86,7 +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.__iter__ \ - pandas.Series.keys \ pandas.Series.item \ pandas.Series.pipe \ pandas.Series.mode \ @@ -535,7 +534,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.DataFrame.index \ pandas.DataFrame.columns \ pandas.DataFrame.__iter__ \ - pandas.DataFrame.keys \ pandas.DataFrame.iterrows \ pandas.DataFrame.pipe \ pandas.DataFrame.backfill \ From 7df3c3ecff20bd9d9d06bc3467e96d99fac0f188 Mon Sep 17 00:00:00 2001 From: Dea Leon Date: Wed, 26 Apr 2023 17:37:01 +0200 Subject: [PATCH 3/4] DOC Removed lines from code_check --- ci/code_checks.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 1880725cefabe..d450630227e2a 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -85,7 +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.item \ pandas.Series.pipe \ pandas.Series.mode \ @@ -532,7 +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.iterrows \ pandas.DataFrame.pipe \ pandas.DataFrame.backfill \ From 09e07be7448c1fc0b186e0db9a12cc82c7d71386 Mon Sep 17 00:00:00 2001 From: Dea Leon Date: Thu, 27 Apr 2023 17:55:17 +0200 Subject: [PATCH 4/4] DOC examples __iter__ not needed? --- pandas/core/base.py | 2 +- pandas/core/generic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index dfc3db83d5470..b281dace12fcb 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -740,7 +740,7 @@ def __iter__(self) -> Iterator: Examples -------- >>> s = pd.Series([1, 2, 3]) - >>> for x in s.__iter__(): + >>> for x in s: ... print(x) 1 2 diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2d03b5a707fdd..1dc0981946533 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1904,7 +1904,7 @@ def __iter__(self) -> Iterator: Examples -------- >>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) - >>> for x in df.__iter__(): + >>> for x in df: ... print(x) A B