From 6814d816f088ffa9ea7226cbe7401c66bb40e07d Mon Sep 17 00:00:00 2001 From: debnathshoham Date: Mon, 23 Aug 2021 22:20:06 +0530 Subject: [PATCH 1/2] TST: MultiIndex with complex --- .../indexing/multiindex/test_multiindex.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pandas/tests/indexing/multiindex/test_multiindex.py b/pandas/tests/indexing/multiindex/test_multiindex.py index 41c2c61154f08..0190ea3712002 100644 --- a/pandas/tests/indexing/multiindex/test_multiindex.py +++ b/pandas/tests/indexing/multiindex/test_multiindex.py @@ -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, + } + ) + 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) From 53c97dbd4f360f473870c984505dc052c90618fa Mon Sep 17 00:00:00 2001 From: debnathshoham Date: Tue, 24 Aug 2021 12:29:58 +0530 Subject: [PATCH 2/2] simplified as suggested --- pandas/tests/indexing/multiindex/test_multiindex.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/tests/indexing/multiindex/test_multiindex.py b/pandas/tests/indexing/multiindex/test_multiindex.py index 0190ea3712002..b04a76093a002 100644 --- a/pandas/tests/indexing/multiindex/test_multiindex.py +++ b/pandas/tests/indexing/multiindex/test_multiindex.py @@ -101,21 +101,20 @@ def test_multiindex_with_datatime_level_preserves_freq(self): 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] + complex_data = [1 + 2j, 4 - 3j, 10 - 1j] + non_complex_data = [3, 4, 5] result = DataFrame( { "x": complex_data, - "y": non_complex_data1, - "z": non_complex_data2, + "y": non_complex_data, + "z": non_complex_data, } ) result.set_index(["x", "y"], inplace=True) expected = DataFrame( - {"z": non_complex_data2}, + {"z": non_complex_data}, index=MultiIndex.from_arrays( - [complex_data, non_complex_data1], + [complex_data, non_complex_data], names=("x", "y"), ), )