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
17 changes: 17 additions & 0 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,23 @@ 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])
idx = pd.Index([tuple_1, tuple_2], name="A", tupleize_cols=False)
df = DataFrame(index=idx)

result = df.loc[[tuple_1]]
idx_1 = pd.Index([tuple_1], name="A", tupleize_cols=False)
expected = DataFrame(index=idx_1)
tm.assert_frame_equal(result, expected)

result = df.loc[[tuple_2]]
idx_2 = pd.Index([tuple_2], name="A", tupleize_cols=False)
expected = DataFrame(index=idx_2)
tm.assert_frame_equal(result, expected)

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