Repository: dask/dask
Pull request #10804 (2024-01-16 10:48:49)

Improve tests for `to_numeric`
- [ ] Closes #xxxx
- [ ] Tests added / passed
- [ ] Passes `pre-commit run --all-files`



Patch:
diff --git a/dask/dataframe/core.py b/dask/dataframe/core.py
index 79091a18d..ca09cb9c8 100644
--- a/dask/dataframe/core.py
+++ b/dask/dataframe/core.py
@@ -2158,6 +2158,7 @@ Dask Name: {name}, {layers}"""
         else:
             return lambda self, other: elemwise(op, self, other)
 
+    @_deprecated_kwarg("axis", None)
     def rolling(
         self, window, min_periods=None, center=False, win_type=None, axis=no_default
     ):


Test patch:
diff --git a/dask/dataframe/tests/test_numeric.py b/dask/dataframe/tests/test_numeric.py
index 246792154..785f8e7ea 100644
--- a/dask/dataframe/tests/test_numeric.py
+++ b/dask/dataframe/tests/test_numeric.py
@@ -5,10 +5,12 @@ import pandas as pd
 import pytest
 
 from dask.array import Array, from_array
-from dask.dataframe import Series, from_pandas, to_numeric
+from dask.dataframe import Series, _dask_expr_enabled, from_pandas, to_numeric
 from dask.dataframe.utils import pyarrow_strings_enabled
 from dask.delayed import Delayed
 
+DASK_EXPR_ENABLED = _dask_expr_enabled()
+
 
 @pytest.mark.parametrize("arg", ["5", 5, "5 "])
 def test_to_numeric_on_scalars(arg):
@@ -21,6 +23,18 @@ def test_to_numeric_on_dask_array():
     arg = from_array(["1.0", "2", "-3", "5.1"])
     expected = np.array([1.0, 2.0, -3.0, 5.1])
     output = to_numeric(arg)
+    expected_dtype = "int64"
+    assert output.dtype == expected_dtype
+    assert isinstance(output, Array)
+    assert list(output.compute()) == list(expected)
+
+
+def test_to_numeric_on_dask_array_with_meta():
+    arg = from_array(["1.0", "2", "-3", "5.1"])
+    expected = np.array([1.0, 2.0, -3.0, 5.1])
+    output = to_numeric(arg, meta=np.array((), dtype="float64"))
+    expected_dtype = "float64"
+    assert output.dtype == expected_dtype
     assert isinstance(output, Array)
     assert list(output.compute()) == list(expected)
 
@@ -31,7 +45,7 @@ def test_to_numeric_on_dask_dataframe_series():
     expected = pd.to_numeric(s)
     output = to_numeric(arg)
     expected_dtype = "int64"
-    if pyarrow_strings_enabled():
+    if pyarrow_strings_enabled() and not DASK_EXPR_ENABLED:
         # `to_numeric` output depends on input dtype
         expected_dtype = "Int64"
     assert output.dtype == expected_dtype
diff --git a/dask/dataframe/tests/test_rolling.py b/dask/dataframe/tests/test_rolling.py
index 68338764f..541f7f5f9 100644
--- a/dask/dataframe/tests/test_rolling.py
+++ b/dask/dataframe/tests/test_rolling.py
@@ -330,8 +330,12 @@ def test_rolling_raises():
     pytest.raises(ValueError, lambda: ddf.rolling(-1))
     pytest.raises(ValueError, lambda: ddf.rolling(3, min_periods=1.2))
     pytest.raises(ValueError, lambda: ddf.rolling(3, min_periods=-2))
-    pytest.raises(ValueError, lambda: ddf.rolling(3, axis=10))
-    pytest.raises(ValueError, lambda: ddf.rolling(3, axis="coulombs"))
+
+    axis_deprecated = pytest.warns(FutureWarning, match="'axis' keyword is deprecated")
+    with axis_deprecated:
+        pytest.raises(ValueError, lambda: ddf.rolling(3, axis=10))
+    with axis_deprecated:
+        pytest.raises(ValueError, lambda: ddf.rolling(3, axis="coulombs"))
     pytest.raises(NotImplementedError, lambda: ddf.rolling(100).mean().compute())
 
 
@@ -356,23 +360,31 @@ def test_rolling_axis(kwargs):
     df = pd.DataFrame(np.random.randn(20, 16))
     ddf = dd.from_pandas(df, npartitions=3)
 
-    ctx = contextlib.nullcontext()
+    axis_deprecated_pandas = contextlib.nullcontext()
     if PANDAS_GE_210:
-        ctx = pytest.warns(FutureWarning, match="The 'axis' keyword|Support for axis")
+        axis_deprecated_pandas = pytest.warns(
+            FutureWarning, match="'axis' keyword|Support for axis"
+        )
+
+    axis_deprecated_dask = pytest.warns(
+        FutureWarning, match="'axis' keyword is deprecated"
+    )
 
     if kwargs["axis"] == "series":
         # Series
-        with ctx:
+        with axis_deprecated_pandas:
             expected = df[3].rolling(5, axis=0).std()
-        with ctx:
+        with axis_deprecated_dask:
             result = ddf[3].rolling(5, axis=0).std()
         assert_eq(expected, result)
     else:
         # DataFrame
-        with ctx:
+        with axis_deprecated_pandas:
             expected = df.rolling(3, **kwargs).mean()
         if kwargs["axis"] in (1, "rows") and not PANDAS_GE_210:
             ctx = pytest.warns(FutureWarning, match="Using axis=1 in Rolling")
+        elif "axis" in kwargs:
+            ctx = axis_deprecated_dask
         with ctx:
             result = ddf.rolling(3, **kwargs).mean()
         assert_eq(expected, result)