Skip to content

TST: add test for indexing with single/double tuples #29448

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

Merged
merged 9 commits into from
Nov 20, 2019
14 changes: 14 additions & 0 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,20 @@ def test_index_namedtuple(self):
result = df.loc[IndexType("foo", "bar")]["A"]
assert result == 1

def test_index_single_double_tuples(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

can parameterize this (e.g. pass in what you have as tuple_1, tuple_2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the feedback @jreback - now using parameterize

# GH 20991
tuple_1 = tuple([1, 2])
tuple_2 = tuple([1])
df = DataFrame([[tuple_1], [tuple_2]], columns=["A"]).set_index("A")
Copy link
Member

Choose a reason for hiding this comment

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

Can you just construct idx = pd.Index(...) before this and use index=idx as part of the DataFrame constructors? Would be more concise than the current construction / set_index ops

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @WillAyd - removed .set_index()


result = df.loc[[df.index[0]]]
Copy link
Member

Choose a reason for hiding this comment

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

df.loc[tuple_1]; if you can avoid df.index[...] calls here will make the test more concise, as accessing index values like that isn't related to the test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @WillAyd - removed .index[...]

expected = DataFrame([[tuple_1]], columns=["A"]).set_index("A")
tm.assert_frame_equal(result, expected)

result = df.loc[[df.index[1]]]
expected = DataFrame([[tuple_2]], columns=["A"]).set_index("A")
tm.assert_frame_equal(result, expected)

def test_boolean_indexing(self):
idx = list(range(3))
cols = ["A", "B", "C"]
Expand Down