Skip to content

Commit 3058713

Browse files
authored
CLN/TST: test_series_align_multiindex_containing_nan (pandas-dev#50516)
* CLN/TST: test_series_align_multiindex_containing_nan * split test into two
1 parent 7c4b98e commit 3058713

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

pandas/tests/indexing/multiindex/test_multiindex.py

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -151,57 +151,35 @@ def test_rename_multiindex_with_duplicates(self):
151151
expected = DataFrame(index=mi2)
152152
tm.assert_frame_equal(df, expected)
153153

154-
@pytest.mark.parametrize(
155-
"data_result, data_expected",
156-
[
157-
(
158-
[
159-
[(81.0, np.nan), (np.nan, np.nan)],
160-
[(np.nan, np.nan), (82.0, np.nan)],
161-
[1, 2],
162-
[1, 2],
163-
],
164-
[
165-
[[81, 82.0, np.nan], Series([np.nan, np.nan, np.nan])],
166-
[[81, 82.0, np.nan], Series([np.nan, np.nan, np.nan])],
167-
[1, np.nan, 2],
168-
[np.nan, 2, 1],
169-
],
170-
),
171-
(
172-
[
173-
[(81.0, np.nan), (np.nan, np.nan)],
174-
[(np.nan, np.nan), (81.0, np.nan)],
175-
[1, 2],
176-
[1, 2],
177-
],
178-
[
179-
[[81.0, np.nan], Series([np.nan, np.nan])],
180-
[[81.0, np.nan], Series([np.nan, np.nan])],
181-
[1, 2],
182-
[2, 1],
183-
],
184-
),
185-
],
186-
)
187-
def test_subtracting_two_series_with_unordered_index_and_all_nan_index(
188-
self, data_result, data_expected
189-
):
154+
def test_series_align_multiindex_with_nan_overlap_only(self):
155+
# GH 38439
156+
mi1 = MultiIndex.from_arrays([[81.0, np.nan], [np.nan, np.nan]])
157+
mi2 = MultiIndex.from_arrays([[np.nan, 82.0], [np.nan, np.nan]])
158+
ser1 = Series([1, 2], index=mi1)
159+
ser2 = Series([1, 2], index=mi2)
160+
result1, result2 = ser1.align(ser2)
161+
162+
mi = MultiIndex.from_arrays([[81.0, 82.0, np.nan], [np.nan, np.nan, np.nan]])
163+
expected1 = Series([1.0, np.nan, 2.0], index=mi)
164+
expected2 = Series([np.nan, 2.0, 1.0], index=mi)
165+
166+
tm.assert_series_equal(result1, expected1)
167+
tm.assert_series_equal(result2, expected2)
168+
169+
def test_series_align_multiindex_with_nan(self):
190170
# GH 38439
191-
# TODO: Refactor. This is impossible to understand GH#49443
192-
a_index_result = MultiIndex.from_tuples(data_result[0])
193-
b_index_result = MultiIndex.from_tuples(data_result[1])
194-
a_series_result = Series(data_result[2], index=a_index_result)
195-
b_series_result = Series(data_result[3], index=b_index_result)
196-
result = a_series_result.align(b_series_result)
197-
198-
a_index_expected = MultiIndex.from_arrays(data_expected[0])
199-
b_index_expected = MultiIndex.from_arrays(data_expected[1])
200-
a_series_expected = Series(data_expected[2], index=a_index_expected)
201-
b_series_expected = Series(data_expected[3], index=b_index_expected)
202-
203-
tm.assert_series_equal(result[0], a_series_expected)
204-
tm.assert_series_equal(result[1], b_series_expected)
171+
mi1 = MultiIndex.from_arrays([[81.0, np.nan], [np.nan, np.nan]])
172+
mi2 = MultiIndex.from_arrays([[np.nan, 81.0], [np.nan, np.nan]])
173+
ser1 = Series([1, 2], index=mi1)
174+
ser2 = Series([1, 2], index=mi2)
175+
result1, result2 = ser1.align(ser2)
176+
177+
mi = MultiIndex.from_arrays([[81.0, np.nan], [np.nan, np.nan]])
178+
expected1 = Series([1, 2], index=mi)
179+
expected2 = Series([2, 1], index=mi)
180+
181+
tm.assert_series_equal(result1, expected1)
182+
tm.assert_series_equal(result2, expected2)
205183

206184
def test_nunique_smoke(self):
207185
# GH 34019

0 commit comments

Comments
 (0)