-
-
Notifications
You must be signed in to change notification settings - Fork 144
GH1217 Modify items/iterros/itertuples methods to return Iterator #1225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fe68e48
6d15f0c
5a7fe40
1f91170
d0a5bf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -599,32 +599,75 @@ def test_types_median() -> None: | |
def test_types_iterrows() -> None: | ||
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]}) | ||
check( | ||
assert_type(df.iterrows(), "Iterable[tuple[Hashable, pd.Series]]"), | ||
assert_type(df.iterrows(), "Iterator[tuple[Hashable, pd.Series]]"), | ||
Iterable, | ||
tuple, | ||
) | ||
for t1, t2 in df.iterrows(): | ||
check(assert_type(t1, Hashable), Hashable) | ||
check(assert_type(t2, pd.Series), pd.Series) | ||
|
||
|
||
def test_types_itertuples() -> None: | ||
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]}) | ||
check( | ||
assert_type(df.itertuples(), Iterable[_PandasNamedTuple]), | ||
Iterable, | ||
assert_type(df.itertuples(), Iterator[_PandasNamedTuple]), | ||
Iterator, | ||
_PandasNamedTuple, | ||
) | ||
check( | ||
assert_type( | ||
df.itertuples(index=False, name="Foobar"), Iterable[_PandasNamedTuple] | ||
df.itertuples(index=False, name="Foobar"), Iterator[_PandasNamedTuple] | ||
), | ||
Iterable, | ||
Iterator, | ||
_PandasNamedTuple, | ||
) | ||
check( | ||
assert_type(df.itertuples(index=False, name=None), Iterable[tuple[Any, ...]]), | ||
Iterable, | ||
assert_type(df.itertuples(index=False, name=None), Iterator[tuple[Any, ...]]), | ||
Iterator, | ||
object, | ||
) | ||
|
||
for t1 in df.itertuples(): | ||
assert_type(t1, _PandasNamedTuple) | ||
assert t1.__class__.__name__ == "Pandas" | ||
assert isinstance(t1.Index, int) | ||
assert isinstance(t1.col1, int) | ||
assert isinstance(t1.col2, int) | ||
for k in [0, 1]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop and the one below should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh yes correct I thought it was iterating over the number of elements. |
||
assert isinstance(t1[k], int) | ||
|
||
for t1 in df.itertuples(name="FooBar"): | ||
assert_type(t1, _PandasNamedTuple) | ||
assert t1.__class__.__name__ == "FooBar" | ||
assert isinstance(t1.Index, int) | ||
assert isinstance(t1.col1, int) | ||
assert isinstance(t1.col2, int) | ||
for k in [0, 1]: | ||
assert isinstance(t1[k], int) | ||
|
||
|
||
def test_types_items() -> None: | ||
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]}) | ||
check( | ||
assert_type(df.items(), Iterator[tuple[Hashable, pd.Series]]), | ||
Iterator, | ||
tuple, | ||
) | ||
|
||
for t1, t2 in df.items(): | ||
check(assert_type(t1, Hashable), Hashable) | ||
check(assert_type(t2, pd.Series), pd.Series) | ||
|
||
|
||
def test_frame_iterator() -> None: | ||
"""Test iterator methods for a dataframe GH1217.""" | ||
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]}) | ||
|
||
check(assert_type(next(df.items()), tuple[Hashable, "pd.Series"]), tuple) | ||
check(assert_type(next(df.iterrows()), tuple[Hashable, "pd.Series"]), tuple) | ||
check(assert_type(next(df.itertuples()), _PandasNamedTuple), _PandasNamedTuple) | ||
|
||
|
||
def test_types_sum() -> None: | ||
df = pd.DataFrame(data={"col1": [2, 1], "col2": [3, 4]}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test of this form for
iterrows()
anditertuples()
: