Skip to content
Open
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ Other enhancements
- Added a new :meth:`DataFrame.from_arrow` method to import any Arrow-compatible
tabular data object into a pandas :class:`DataFrame` through the
`Arrow PyCapsule Protocol <https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html>`__ (:issue:`59631`)
- :meth:`DataFrame.itertuples` is now annotated to return an iterable of Any to accommodate dynamic namedtuple types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pandas publishes type-hints through pandas-stubs, the ones in the pandas library itself do not impact users. As this is not a user-facing change, the whatsnew note should be removed.


.. ---------------------------------------------------------------------------
.. _whatsnew_300.notable_bug_fixes:
Expand Down
10 changes: 9 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,9 +1598,17 @@ def iterrows(self) -> Iterable[tuple[Hashable, Series]]:
s._mgr.add_references(self._mgr)
yield k, s

@overload
def itertuples(self, index: bool, name: None) -> Iterable[tuple[Any, ...]]:
...

@overload
def itertuples(self, index: bool, name: str) -> Iterable[Any]:
...

def itertuples(
self, index: bool = True, name: str | None = "Pandas"
) -> Iterable[tuple[Any, ...]]:
) -> Iterable[tuple[Any, ...]] | Iterable[Any]:
"""
Iterate over DataFrame rows as namedtuples.

Expand Down
Loading