Skip to content

Commit a93e2e2

Browse files
authored
51500: Add test for unexpected behavior math operations using multiin… (pandas-dev#59191)
51500: Add test for unexpected behavior math operations using multiindexes
1 parent 61c5fbf commit a93e2e2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/indexing/multiindex/test_multiindex.py

+17
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,20 @@ def test_multiindex_from_tuples_with_nan(self):
232232
[("a", "b", "c"), (np.nan, np.nan, np.nan), ("d", "", "")]
233233
)
234234
tm.assert_index_equal(result, expected)
235+
236+
@pytest.mark.parametrize("operation", ["div", "mul", "add", "sub"])
237+
def test_groupyby_rename_categories_operation_with_multiindex(self, operation):
238+
# GH#51500
239+
data = DataFrame(
240+
[["C", "B", "B"], ["B", "A", "A"], ["B", "A", "B"]], columns=["0", "1", "2"]
241+
)
242+
data["0"] = data["0"].astype("category")
243+
data["0"] = data["0"].cat.rename_categories({"C": "B", "B": "C"})
244+
245+
a = data.groupby(by=["0", "1"])["2"].value_counts()
246+
b = data.groupby(by=["0", "1"]).size()
247+
248+
result = getattr(a, operation)(b)
249+
expected = getattr(a, operation)(b.sort_index(ascending=False))
250+
251+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)