Skip to content

Commit 2aadf0e

Browse files
Refine iterrows and itertuples return types (#822)
refine iterrows and itertuples return types * Added first test on iterrows. * Updated iterrows return type to Iterable[tuple[Hashable, Series]]. * Added return type Iterable[tuple[Any, ...]] to itertuples.
1 parent 536db83 commit 2aadf0e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pandas-stubs/core/frame.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ class DataFrame(NDFrame, OpsMixin):
247247
@property
248248
def style(self) -> Styler: ...
249249
def items(self) -> Iterable[tuple[Hashable, Series]]: ...
250-
def iterrows(self) -> Iterable[tuple[Label, Series]]: ...
251-
def itertuples(self, index: _bool = ..., name: _str | None = ...): ...
250+
def iterrows(self) -> Iterable[tuple[Hashable, Series]]: ...
251+
def itertuples(
252+
self, index: _bool = ..., name: _str | None = ...
253+
) -> Iterable[tuple[Any, ...]]: ...
252254
def __len__(self) -> int: ...
253255
@overload
254256
def dot(self, other: DataFrame | ArrayLike) -> DataFrame: ...

tests/test_frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
getSeriesData,
3434
)
3535
from pandas.core.resample import Resampler # noqa: F401
36+
from pandas.core.series import Series
3637
import pytest
3738
from typing_extensions import assert_type
3839
import xarray as xr
@@ -403,6 +404,11 @@ def test_types_median() -> None:
403404
s3: pd.Series = df.median(axis=1, skipna=True, numeric_only=False)
404405

405406

407+
def test_types_iterrows() -> None:
408+
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
409+
res1: Iterable[tuple[Hashable, Series]] = df.iterrows()
410+
411+
406412
def test_types_itertuples() -> None:
407413
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]})
408414
res1: Iterable[tuple[Any, ...]] = df.itertuples()

0 commit comments

Comments
 (0)