Skip to content
Merged
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ def test_types_iterrows() -> None:
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:
Expand All @@ -625,6 +628,9 @@ def test_types_itertuples() -> None:
object,
)

for t1 in df.itertuples():
check(assert_type(t1, _PandasNamedTuple), _PandasNamedTuple)

Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't be using _PandasNamedTuple here in the call to check because what is happening internally is that pandas is creating a new class of type pandas.core.foo.Pandas, and if you use the name="Foobar" argument, the class is of the type pandas.core.foo.Foobar

But it's a dynamic class, so I think something like this would be appropriate:

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, 2]:
        assert(isinstance(t1[k], int))

And you could add a similar test for having name="Foobar" as the argument, and only the line that checks the name of the class would need to be changed.


def test_frame_iterator() -> None:
"""Test iterator methods for a dataframe GH1217."""
Expand Down