Skip to content
Merged
Changes from 2 commits
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
16 changes: 16 additions & 0 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,22 @@ def test_type_error_multiindex(self):
result = dg["x", 0]
tm.assert_series_equal(result, expected)

def test_tuple_string_column_names(self):
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 move this to pandas/tests/indexing/multiindex/test_getitem.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done @mroeschke

# GH#50372
mi = MultiIndex.from_tuples(
[("a", "aa"), ("a", "ab"), ("b", "ba"), ("b", "bb")]
)
df = DataFrame([range(0, 4), range(1, 5), range(2, 6)], columns=mi)
df["single_index"] = 0

df_flat = df.copy()
df_flat.columns = df_flat.columns.to_flat_index()
df_flat["new_single_index"] = 0

df_flat = df_flat[[("a", "aa"), "new_single_index"]]

assert df_flat.columns.equals(Index([("a", "aa"), "new_single_index"]))
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 construct the full pandas object result of df_flat and use tm.assert_equal?

result = df_flat[[("a", "aa"), "new_single_index"]]
expected = ...
tm.assert_equal(result, expected)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also done (: @mroeschke


def test_getitem_interval_index_partial_indexing(self):
# GH#36490
df = DataFrame(
Expand Down