Skip to content

Commit 1d96b4d

Browse files
authored
Annotate __iter__ method of Series (#126)
1 parent 2fd9697 commit 1d96b4d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

pandas-stubs/core/generic.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
9494
def bool(self) -> _bool: ...
9595
def __abs__(self) -> NDFrame: ...
9696
def __round__(self, decimals: int = ...) -> NDFrame: ...
97-
def __iter__(self) -> Iterator: ...
9897
def keys(self): ...
9998
def iteritems(self): ...
10099
def __len__(self) -> int: ...

pandas-stubs/core/series.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from typing import (
1010
Generic,
1111
Hashable,
1212
Iterable,
13+
Iterator,
1314
List,
1415
Literal,
1516
Mapping,
@@ -1772,6 +1773,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
17721773
def set_axis(
17731774
self, labels, axis: Axis = ..., inplace: bool = ...
17741775
) -> Optional[Series[S1]]: ...
1776+
def __iter__(self) -> Iterator[S1]: ...
17751777

17761778
class TimestampSeries(Series): ...
17771779

tests/test_series.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import tempfile
33
from typing import (
44
TYPE_CHECKING,
5+
Iterable,
6+
Iterator,
57
List,
68
Sequence,
79
Union,
@@ -787,3 +789,10 @@ def test_iloc_setitem_ndarray() -> None:
787789
values_s.iloc[indices_u16] = -1
788790
values_s.iloc[indices_u32] = -1
789791
values_s.iloc[indices_u64] = -1
792+
793+
794+
def test_types_iter() -> None:
795+
s = pd.Series([1, 2, 3], dtype=int)
796+
iterable: Iterable[int] = s
797+
assert_type(iter(s), Iterator[int])
798+
assert_type(next(iter(s)), int)

0 commit comments

Comments
 (0)