You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several iteration methods in pandas(-stubs) specify their return type as Iterable while they are implemented as generators or return zip objects which qualify them as Iterator. This flags straight-forward use with next, which should be perfectly valid. Most of them are documented to return an Iterator as per the docstring and it seems reasonable to assume that they actually return iterators.
DataFrame.itertuples - Documented to "Iterate over" and return an "iterator", returns a zip object
DataFrame.iterrows - Documented to "Iterate over", Generator function
DataFrame.items - Documented to "Iterate over", Generator function
Series.items - Documented to "Lazily iterate over", Generator function
To Reproduce
import pandas as pd
def foo(df: pd.DataFrame):
next(df.items())
(mypy)
test.py:4: error: No overload variant of "next" matches argument type "Iterable[tuple[Hashable, Series[Any]]]" [call-overload]
test.py:4: note: Possible overload variants:
test.py:4: note: def [_T] next(SupportsNext[_T], /) -> _T
test.py:4: note: def [_T, _VT] next(SupportsNext[_T], _VT, /) -> _T | _VT
Found 1 error in 1 file (checked 1 source file)
Please complete the following information:
OS: Linux
python 3.12.3
mypy 1.15.0
pandas-stubs 2.2.3.250308
Additional context
This also affects the type within the main pandas code, should I make another issue there?
Describe the bug
Several iteration methods in pandas(-stubs) specify their return type as
Iterable
while they are implemented as generators or return zip objects which qualify them asIterator
. This flags straight-forward use withnext
, which should be perfectly valid. Most of them are documented to return an Iterator as per the docstring and it seems reasonable to assume that they actually return iterators.DataFrame.itertuples
- Documented to "Iterate over" and return an "iterator", returns azip
objectDataFrame.iterrows
- Documented to "Iterate over", Generator functionDataFrame.items
- Documented to "Iterate over", Generator functionSeries.items
- Documented to "Lazily iterate over", Generator functionTo Reproduce
(mypy)
Please complete the following information:
Additional context
The text was updated successfully, but these errors were encountered: