Skip to content

TST: MultiIndex with complex #43184

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 2 commits into from
Aug 26, 2021
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
22 changes: 22 additions & 0 deletions pandas/tests/indexing/multiindex/test_multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,25 @@ def test_multiindex_with_datatime_level_preserves_freq(self):
result = df.loc[0].index
tm.assert_index_equal(result, dti)
assert result.freq == dti.freq

def test_multiindex_complex(self):
# GH#42145
complex_data = [1 + 2j, 4 - 3j, 10 - 1j, 4 + 5j, 5 - 8j]
non_complex_data1 = [3, 4, 5, 6, 7]
non_complex_data2 = [0.1, 0.2, 0.3, 0.4, 0.5]
result = DataFrame(
{
"x": complex_data,
"y": non_complex_data1,
"z": non_complex_data2,
Copy link
Member

@phofl phofl Aug 23, 2021

Choose a reason for hiding this comment

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

Could you simply use 1 here, makes it easier to understand since this is not bug relevant, isn‘t it?

also maybe reduce number of rows?

Copy link
Member Author

Choose a reason for hiding this comment

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

amended

}
)
result.set_index(["x", "y"], inplace=True)
expected = DataFrame(
{"z": non_complex_data2},
index=MultiIndex.from_arrays(
[complex_data, non_complex_data1],
names=("x", "y"),
),
)
tm.assert_frame_equal(result, expected)