Repository: dask/dask

Issue:
Deprecate axis in GroupBy cumulative transformers
Deprecate axis in

- cumsum
- cumprod
- cumcount

and please skip tests that test this behaviour for dask-expr


Discussion:

Patch:
diff --git a/dask/dataframe/groupby.py b/dask/dataframe/groupby.py
--- a/dask/dataframe/groupby.py
+++ b/dask/dataframe/groupby.py
@@ -48,7 +48,14 @@
 )
 from dask.highlevelgraph import HighLevelGraph
 from dask.typing import no_default
-from dask.utils import M, _deprecated, derived_from, funcname, itemgetter
+from dask.utils import (
+    M,
+    _deprecated,
+    _deprecated_kwarg,
+    derived_from,
+    funcname,
+    itemgetter,
+)
 
 if PANDAS_GE_140:
     from pandas.core.apply import reconstruct_func, validate_func_kwargs
@@ -1763,6 +1770,7 @@ def _shuffle(self, meta):
 
         return df4, by2
 
+    @_deprecated_kwarg("axis", None)
     @derived_from(pd.core.groupby.GroupBy)
     def cumsum(self, axis=no_default, numeric_only=no_default):
         axis = self._normalize_axis(axis, "cumsum")
@@ -1779,6 +1787,7 @@ def cumsum(self, axis=no_default, numeric_only=no_default):
                 numeric_only=numeric_only,
             )
 
+    @_deprecated_kwarg("axis", None)
     @derived_from(pd.core.groupby.GroupBy)
     def cumprod(self, axis=no_default, numeric_only=no_default):
         axis = self._normalize_axis(axis, "cumprod")
@@ -1795,14 +1804,9 @@ def cumprod(self, axis=no_default, numeric_only=no_default):
                 numeric_only=numeric_only,
             )
 
+    @_deprecated_kwarg("axis", None)
     @derived_from(pd.core.groupby.GroupBy)
     def cumcount(self, axis=no_default):
-        if axis is not no_default:
-            warnings.warn(
-                "The `axis` keyword argument is deprecated and will removed in a future release. "
-                "Previously it was unused and had no effect.",
-                FutureWarning,
-            )
         return self._cum_agg(
             "cumcount", chunk=M.cumcount, aggregate=_cumcount_aggregate, initial=-1
         )


Test patch:
diff --git a/dask/dataframe/tests/test_groupby.py b/dask/dataframe/tests/test_groupby.py
--- a/dask/dataframe/tests/test_groupby.py
+++ b/dask/dataframe/tests/test_groupby.py
@@ -1761,13 +1761,6 @@ def test_cumulative(func, key, sel):
     g, dg = (d.groupby(key)[sel] for d in (df, ddf))
     assert_eq(getattr(g, func)(), getattr(dg, func)())
 
-    if func == "cumcount":
-        with pytest.warns(
-            FutureWarning,
-            match="`axis` keyword argument is deprecated and will removed in a future release",
-        ):
-            dg.cumcount(axis=0)
-
 
 def test_series_groupby_multi_character_column_name():
     df = pd.DataFrame({"aa": [1, 2, 1, 3, 4, 1, 2]})
@@ -1775,6 +1768,7 @@ def test_series_groupby_multi_character_column_name():
     assert_eq(df.groupby("aa").aa.cumsum(), ddf.groupby("aa").aa.cumsum())
 
 
+@pytest.mark.skipif(DASK_EXPR_ENABLED, reason="`axis` deprecated in dask-expr")
 @pytest.mark.parametrize("func", ["cumsum", "cumprod"])
 def test_cumulative_axis(func):
     df = pd.DataFrame(
@@ -1792,34 +1786,33 @@ def test_cumulative_axis(func):
     result = getattr(ddf.groupby("a"), func)()
     assert_eq(expected, result)
 
+    axis_deprecated = contextlib.nullcontext()
+    if not PANDAS_GE_210:
+        axis_deprecated = pytest.warns(
+            FutureWarning, match="'axis' keyword is deprecated"
+        )
+
     # axis=0
     with groupby_axis_deprecated():
         expected = getattr(df.groupby("a"), func)(axis=0)
-    with groupby_axis_deprecated():
+    with groupby_axis_deprecated(axis_deprecated):
         result = getattr(ddf.groupby("a"), func)(axis=0)
     assert_eq(expected, result)
 
-    # axis=1
-    deprecate_ctx = pytest.warns(
-        FutureWarning,
-        match="Using axis=1 in GroupBy does not require grouping and will be removed entirely in a future version",
-    )
+    # # axis=1
     with groupby_axis_deprecated():
         expected = getattr(df.groupby("a"), func)(axis=1)
-    with groupby_axis_deprecated(
-        contextlib.nullcontext() if PANDAS_GE_210 else deprecate_ctx
-    ):
+    with groupby_axis_deprecated(axis_deprecated):
         result = getattr(ddf.groupby("a"), func)(axis=1)
     assert_eq(expected, result)
 
-    with deprecate_ctx:
-        with pytest.raises(ValueError, match="No axis named 1 for object type Series"):
-            getattr(ddf.groupby("a").b, func)(axis=1)
-
-    with pytest.warns(
-        FutureWarning,
-        match="`axis` keyword argument is deprecated and will removed in a future release",
+    with groupby_axis_deprecated(
+        pytest.raises(ValueError, match="No axis named 1 for object type Series"),
+        axis_deprecated,
     ):
+        getattr(ddf.groupby("a").b, func)(axis=1)
+
+    with pytest.warns(FutureWarning, match="'axis' keyword is deprecated"):
         ddf.groupby("a").cumcount(axis=1)