Skip to content

Testcase Subtracting two series with unordered index and all-nan index produces unexpected result #45900

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
Changes from all 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
64 changes: 64 additions & 0 deletions pandas/tests/indexing/multiindex/test_multiindex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

import pandas._libs.index as _index
from pandas.errors import PerformanceWarning
Expand Down Expand Up @@ -149,3 +150,66 @@ def test_rename_multiindex_with_duplicates(self):
mi2 = MultiIndex.from_tuples([("Apple", "cat"), ("B", "cat"), ("B", "cat")])
expected = DataFrame(index=mi2)
tm.assert_frame_equal(df, expected)

@pytest.mark.parametrize(
"data_result, data_expected",
[
(
[
[(81.0, np.nan), (np.nan, np.nan)],
[(np.nan, np.nan), (82.0, np.nan)],
[1, 2],
[1, 2],
],
[
[(81.0, np.nan), (np.nan, np.nan)],
[(81.0, np.nan), (np.nan, np.nan)],
[1, 2],
[1, 1],
],
),
(
[
[(81.0, np.nan), (np.nan, np.nan)],
[(np.nan, np.nan), (81.0, np.nan)],
[1, 2],
[1, 2],
],
[
[(81.0, np.nan), (np.nan, np.nan)],
[(81.0, np.nan), (np.nan, np.nan)],
[1, 2],
[2, 1],
],
),
],
)
def test_subtracting_two_series_with_unordered_index_and_all_nan_index(
self, data_result, data_expected
):
# GH 38439
a_index_result = MultiIndex.from_tuples(data_result[0])
b_index_result = MultiIndex.from_tuples(data_result[1])
a_series_result = Series(data_result[2], index=a_index_result)
b_series_result = Series(data_result[3], index=b_index_result)
result = a_series_result.align(b_series_result)

a_index_expected = MultiIndex.from_tuples(data_expected[0])
b_index_expected = MultiIndex.from_tuples(data_expected[1])
a_series_expected = Series(data_expected[2], index=a_index_expected)
b_series_expected = Series(data_expected[3], index=b_index_expected)
a_series_expected.index = a_series_expected.index.set_levels(
[
a_series_expected.index.levels[0].astype("float"),
a_series_expected.index.levels[1].astype("float"),
]
)
b_series_expected.index = b_series_expected.index.set_levels(
[
b_series_expected.index.levels[0].astype("float"),
b_series_expected.index.levels[1].astype("float"),
]
)

tm.assert_series_equal(result[0], a_series_expected)
tm.assert_series_equal(result[1], b_series_expected)