55import pytest
66
77from dask .array import Array , from_array
8- from dask .dataframe import Series , from_pandas , to_numeric
8+ from dask .dataframe import Series , _dask_expr_enabled , from_pandas , to_numeric
99from dask .dataframe .utils import pyarrow_strings_enabled
1010from dask .delayed import Delayed
1111
12+ DASK_EXPR_ENABLED = _dask_expr_enabled ()
13+
1214
1315@pytest .mark .parametrize ("arg" , ["5" , 5 , "5 " ])
1416def test_to_numeric_on_scalars (arg ):
@@ -21,6 +23,18 @@ def test_to_numeric_on_dask_array():
2123 arg = from_array (["1.0" , "2" , "-3" , "5.1" ])
2224 expected = np .array ([1.0 , 2.0 , - 3.0 , 5.1 ])
2325 output = to_numeric (arg )
26+ expected_dtype = "int64"
27+ assert output .dtype == expected_dtype
28+ assert isinstance (output , Array )
29+ assert list (output .compute ()) == list (expected )
30+
31+
32+ def test_to_numeric_on_dask_array_with_meta ():
33+ arg = from_array (["1.0" , "2" , "-3" , "5.1" ])
34+ expected = np .array ([1.0 , 2.0 , - 3.0 , 5.1 ])
35+ output = to_numeric (arg , meta = np .array ((), dtype = "float64" ))
36+ expected_dtype = "float64"
37+ assert output .dtype == expected_dtype
2438 assert isinstance (output , Array )
2539 assert list (output .compute ()) == list (expected )
2640
@@ -31,7 +45,7 @@ def test_to_numeric_on_dask_dataframe_series():
3145 expected = pd .to_numeric (s )
3246 output = to_numeric (arg )
3347 expected_dtype = "int64"
34- if pyarrow_strings_enabled ():
48+ if pyarrow_strings_enabled () and not DASK_EXPR_ENABLED :
3549 # `to_numeric` output depends on input dtype
3650 expected_dtype = "Int64"
3751 assert output .dtype == expected_dtype
0 commit comments