Repository: modin-project/modin

Issue:
Implement `level` parameter for kurt/kurtosis functions in modin style



Discussion:
See #1427 for details

Resolving patch:
diff --git a/modin/pandas/base.py b/modin/pandas/base.py
--- a/modin/pandas/base.py
+++ b/modin/pandas/base.py
@@ -1470,17 +1470,17 @@ def kurt(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs):
         Returns:
             kurtosis : Series or DataFrame (if level specified)
         """
+        axis = self._get_axis_number(axis)
         if level is not None:
-            return self._default_to_pandas(
-                "kurt",
-                axis=axis,
-                skipna=skipna,
-                level=level,
-                numeric_only=numeric_only,
-                **kwargs,
-            )
+            func_kwargs = {
+                "axis": axis,
+                "skipna": skipna,
+                "level": level,
+                "numeric_only": numeric_only,
+            }
+
+            return self.apply("kurt", **func_kwargs)
 
-        axis = self._get_axis_number(axis)
         if numeric_only:
             self._validate_dtypes(numeric_only=True)
         return self._reduce_dimension(


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
@@ -2310,22 +2310,35 @@ def test_interpolate(self):
     @pytest.mark.parametrize("skipna", bool_arg_values, ids=bool_arg_keys)
     @pytest.mark.parametrize("level", [None, -1, 0, 1])
     @pytest.mark.parametrize("numeric_only", bool_arg_values, ids=bool_arg_keys)
-    @pytest.mark.parametrize("method", ["kurtosis", "kurt"])
-    def test_kurt_kurtosis(self, axis, skipna, level, numeric_only, method):
+    def test_kurt_kurtosis(self, axis, skipna, level, numeric_only):
+        func_kwargs = {
+            "axis": axis,
+            "skipna": skipna,
+            "level": level,
+            "numeric_only": numeric_only,
+        }
         data = test_data_values[0]
-        modin_df, pandas_df = pd.DataFrame(data), pandas.DataFrame(data)
-        try:
-            pandas_result = getattr(pandas_df, method)(
-                axis, skipna, level, numeric_only
+        df_modin = pd.DataFrame(data)
+        df_pandas = pandas.DataFrame(data)
+
+        eval_general(
+            df_modin, df_pandas, lambda df: df.kurtosis(**func_kwargs),
+        )
+
+        if level is not None:
+            cols_number = len(data.keys())
+            arrays = [
+                np.random.choice(["bar", "baz", "foo", "qux"], cols_number),
+                np.random.choice(["one", "two"], cols_number),
+            ]
+            index = pd.MultiIndex.from_tuples(
+                list(zip(*arrays)), names=["first", "second"]
+            )
+            df_modin.columns = index
+            df_pandas.columns = index
+            eval_general(
+                df_modin, df_pandas, lambda df: df.kurtosis(**func_kwargs),
             )
-        except Exception as e:
-            with pytest.raises(type(e)):
-                repr(
-                    getattr(modin_df, method)(axis, skipna, level, numeric_only)
-                )  # repr to force materialization
-        else:
-            modin_result = getattr(modin_df, method)(axis, skipna, level, numeric_only)
-            df_equals(modin_result, pandas_result)
 
     def test_last(self):
         modin_index = pd.date_range("2010-04-09", periods=400, freq="2D")
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
@@ -1763,19 +1763,17 @@ def test_keys(data):
 )
 @pytest.mark.parametrize("method", ["kurtosis", "kurt"])
 def test_kurt_kurtosis(data, axis, skipna, level, numeric_only, method):
+    func_kwargs = {
+        "axis": axis,
+        "skipna": skipna,
+        "level": level,
+        "numeric_only": numeric_only,
+    }
     modin_series, pandas_series = create_test_series(data)
-    try:
-        pandas_result = getattr(pandas_series, method)(
-            axis, skipna, level, numeric_only
-        )
-    except Exception as e:
-        with pytest.raises(type(e)):
-            repr(
-                getattr(modin_series, method)(axis, skipna, level, numeric_only)
-            )  # repr to force materialization
-    else:
-        modin_result = getattr(modin_series, method)(axis, skipna, level, numeric_only)
-        df_equals(modin_result, pandas_result)
+
+    eval_general(
+        modin_series, pandas_series, lambda df: df.kurtosis(**func_kwargs),
+    )
 
 
 def test_last():