From 7749d9bee6c105d558cc2c1b49d11867968d4ec2 Mon Sep 17 00:00:00 2001 From: G26Karthik Date: Mon, 6 Oct 2025 16:19:57 +0530 Subject: [PATCH 1/3] DOC: Replace @Appender with inline docstring for DataFrame.items - Removed @Appender decorator from DataFrame.items() method - Inlined the complete docstring directly into the method - Addresses issue #62437 to improve docstring clarity and standardization --- pandas/core/frame.py | 48 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 72c9fe51be7f3..1c714eae6f327 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1472,8 +1472,54 @@ def style(self) -> Styler: Name: population, dtype: int64 """ - @Appender(_shared_docs["items"]) def items(self) -> Iterable[tuple[Hashable, Series]]: + """ + Iterate over (column name, Series) pairs. + + Iterates over the DataFrame columns, returning a tuple with + the column name and the content as a Series. + + Yields + ------ + label : object + The column names for the DataFrame being iterated over. + content : Series + The column entries belonging to each label, as a Series. + + See Also + -------- + DataFrame.iterrows : Iterate over DataFrame rows as + (index, Series) pairs. + DataFrame.itertuples : Iterate over DataFrame rows as namedtuples + of the values. + + Examples + -------- + >>> df = pd.DataFrame({'species': ['bear', 'bear', 'marsupial'], + ... 'population': [1864, 22000, 80000]}, + ... index=['panda', 'polar', 'koala']) + >>> df + species population + panda bear 1864 + polar bear 22000 + koala marsupial 80000 + >>> for label, content in df.items(): + ... print(f'label: {label}') + ... print(f'content: {content}', sep='\n') + ... + label: species + content: + panda bear + polar bear + koala marsupial + Name: species, dtype: object + label: population + content: + panda 1864 + polar 22000 + koala 80000 + Name: population, dtype: int64 + """ for i, k in enumerate(self.columns): yield k, self._ixs(i, axis=1) From 031ac50f1bf83bab1ff7b5e1b3f18e3138e581d0 Mon Sep 17 00:00:00 2001 From: G26Karthik Date: Mon, 6 Oct 2025 16:29:11 +0530 Subject: [PATCH 2/3] STY: Apply ruff formatting to DataFrame.items docstring --- pandas/core/frame.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1c714eae6f327..1c36b19a9b17d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1495,18 +1495,21 @@ def items(self) -> Iterable[tuple[Hashable, Series]]: Examples -------- - >>> df = pd.DataFrame({'species': ['bear', 'bear', 'marsupial'], - ... 'population': [1864, 22000, 80000]}, - ... index=['panda', 'polar', 'koala']) + >>> df = pd.DataFrame( + ... { + ... "species": ["bear", "bear", "marsupial"], + ... "population": [1864, 22000, 80000], + ... }, + ... index=["panda", "polar", "koala"], + ... ) >>> df species population panda bear 1864 polar bear 22000 koala marsupial 80000 >>> for label, content in df.items(): - ... print(f'label: {label}') - ... print(f'content: {content}', sep='\n') - ... + ... print(f"label: {label}") + ... print(f"content: {content}", sep="\n") label: species content: panda bear From 51faf57a1889d3a46d235c17d06be0b495fe5338 Mon Sep 17 00:00:00 2001 From: G26Karthik Date: Mon, 6 Oct 2025 17:07:20 +0530 Subject: [PATCH 3/3] FIX: Use raw string for DataFrame.items docstring to handle backslashes --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1c36b19a9b17d..643974db5f2bf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1473,7 +1473,7 @@ def style(self) -> Styler: """ def items(self) -> Iterable[tuple[Hashable, Series]]: - """ + r""" Iterate over (column name, Series) pairs. Iterates over the DataFrame columns, returning a tuple with