Repository: modin-project/modin

Issue:
New API: `reorder_levels` for DataFrame and Series

### Describe the problem
<!-- Describe the problem clearly here. -->
`reorder_levels` only affects the index/columns, so it should be trivial to implement.




Discussion:

Resolving patch:
diff --git a/modin/pandas/base.py b/modin/pandas/base.py
--- a/modin/pandas/base.py
+++ b/modin/pandas/base.py
@@ -2155,6 +2155,11 @@ def f(x):
             if not inplace:
                 return result
 
+    def reorder_levels(self, order, axis=0):
+        axis = self._get_axis_number(axis)
+        new_labels = self.axes[axis].reorder_levels(order)
+        return self.set_axis(new_labels, axis=axis, inplace=False)
+
     def replace(
         self,
         to_replace=None,
diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py
--- a/modin/pandas/dataframe.py
+++ b/modin/pandas/dataframe.py
@@ -1405,11 +1405,6 @@ def _set_axis_name(self, name, axis=0, inplace=False):
         if not inplace:
             return renamed
 
-    def reorder_levels(self, order, axis=0):
-        return self._default_to_pandas(
-            pandas.DataFrame.reorder_levels, order, axis=axis
-        )
-
     def rfloordiv(self, other, axis="columns", level=None, fill_value=None):
         if isinstance(other, Series):
             other = other._to_pandas()
diff --git a/modin/pandas/series.py b/modin/pandas/series.py
--- a/modin/pandas/series.py
+++ b/modin/pandas/series.py
@@ -859,9 +859,6 @@ def rename(self, index=None, **kwargs):
             result.name = self.name
             return result
 
-    def reorder_levels(self, order):
-        return self._default_to_pandas(pandas.Series.reorder_levels, order)
-
     def repeat(self, repeats, axis=None):
         return self._default_to_pandas(pandas.Series.repeat, repeats, axis=axis)
 


Test patch:
diff --git a/modin/pandas/test/test_dataframe.py b/modin/pandas/test/test_dataframe.py
--- a/modin/pandas/test/test_dataframe.py
+++ b/modin/pandas/test/test_dataframe.py
@@ -4769,7 +4769,9 @@ def test_rename_axis_inplace(self):
         df_equals(modin_result, result)
 
     def test_reorder_levels(self):
-        df = pd.DataFrame(
+        data = np.random.randint(1, 100, 12)
+        modin_df = pd.DataFrame(
+            data,
             index=pd.MultiIndex.from_tuples(
                 [
                     (num, letter, color)
@@ -4778,11 +4780,24 @@ def test_reorder_levels(self):
                     for color in ["Red", "Green"]
                 ],
                 names=["Number", "Letter", "Color"],
-            )
+            ),
+        )
+        pandas_df = pandas.DataFrame(
+            data,
+            index=pandas.MultiIndex.from_tuples(
+                [
+                    (num, letter, color)
+                    for num in range(1, 3)
+                    for letter in ["a", "b", "c"]
+                    for color in ["Red", "Green"]
+                ],
+                names=["Number", "Letter", "Color"],
+            ),
+        )
+        df_equals(
+            modin_df.reorder_levels(["Letter", "Color", "Number"]),
+            pandas_df.reorder_levels(["Letter", "Color", "Number"]),
         )
-        df["Value"] = np.random.randint(1, 100, len(df))
-        with pytest.warns(UserWarning):
-            df.reorder_levels(["Letter", "Color", "Number"])
 
     @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
     def test_reset_index(self, data):
diff --git a/modin/pandas/test/test_series.py b/modin/pandas/test/test_series.py
--- a/modin/pandas/test/test_series.py
+++ b/modin/pandas/test/test_series.py
@@ -2122,8 +2122,9 @@ def test_rename(data):
 
 
 def test_reorder_levels():
-    series = pd.Series(
-        np.random.randint(1, 100, 12),
+    data = np.random.randint(1, 100, 12)
+    modin_series = pd.Series(
+        data,
         index=pd.MultiIndex.from_tuples(
             [
                 (num, letter, color)
@@ -2134,8 +2135,21 @@ def test_reorder_levels():
             names=["Number", "Letter", "Color"],
         ),
     )
-    with pytest.warns(UserWarning):
-        series.reorder_levels(["Letter", "Color", "Number"])
+    pandas_series = pandas.Series(
+        data,
+        index=pandas.MultiIndex.from_tuples(
+            [
+                (num, letter, color)
+                for num in range(1, 3)
+                for letter in ["a", "b", "c"]
+                for color in ["Red", "Green"]
+            ],
+            names=["Number", "Letter", "Color"],
+        ),
+    )
+    modin_result = modin_series.reorder_levels(["Letter", "Color", "Number"])
+    pandas_result = pandas_series.reorder_levels(["Letter", "Color", "Number"])
+    df_equals(modin_result, pandas_result)
 
 
 @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)