diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index 1f79672f30f..0ea02edb924 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -5,6 +5,7 @@ import functools import inspect import pickle +import warnings from collections import abc as abc from shutil import get_terminal_size from typing import Any, Dict, MutableMapping, Optional, Set, Tuple, Type, Union @@ -1012,7 +1013,10 @@ def map(self, arg, na_action=None) -> "Series": result.name = self.name result.index = self.index else: - result = self.applymap(arg) + # TODO: switch to `apply` + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=FutureWarning) + result = self.applymap(arg) return result @_cudf_nvtx_annotate @@ -2210,6 +2214,11 @@ def applymap(self, udf, out_dtype=None): 4 105 dtype: int64 """ + warnings.warn( + "Series.applymap is deprecated and will be removed " + "in a future cuDF release. Use Series.apply instead.", + FutureWarning, + ) if not callable(udf): raise ValueError("Input UDF must be a callable object.") return self._from_data({self.name: self._unaryop(udf)}, self._index) diff --git a/python/cudf/cudf/tests/test_applymap.py b/python/cudf/cudf/tests/test_applymap.py index ff6e79e7804..bd322a28a08 100644 --- a/python/cudf/cudf/tests/test_applymap.py +++ b/python/cudf/cudf/tests/test_applymap.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2021, NVIDIA CORPORATION. +# Copyright (c) 2018-2022, NVIDIA CORPORATION. from itertools import product from math import floor @@ -29,9 +29,10 @@ def test_applymap_round(nelem, masked): sr = Series(data) # Call applymap - out = sr.applymap( - lambda x: (floor(x) + 1 if x - floor(x) >= 0.5 else floor(x)) - ) + with pytest.warns(FutureWarning): + out = sr.applymap( + lambda x: (floor(x) + 1 if x - floor(x) >= 0.5 else floor(x)) + ) if masked: # Fill masked values @@ -50,7 +51,8 @@ def test_applymap_change_out_dtype(): sr = Series(data) - out = sr.applymap(lambda x: float(x), out_dtype=float) + with pytest.warns(FutureWarning): + out = sr.applymap(lambda x: float(x), out_dtype=float) # Check expect = np.array(data, dtype=float) diff --git a/python/cudf/cudf/tests/test_transform.py b/python/cudf/cudf/tests/test_transform.py index b5bcf9df8f5..4b4537514d6 100644 --- a/python/cudf/cudf/tests/test_transform.py +++ b/python/cudf/cudf/tests/test_transform.py @@ -29,6 +29,7 @@ def test_applymap_python_lambda(dtype, udf, testfunc): lhs_arr = np.random.random(size).astype(dtype) lhs_ser = Series(lhs_arr) - out_ser = lhs_ser.applymap(udf) + with pytest.warns(FutureWarning): + out_ser = lhs_ser.applymap(udf) result = testfunc(lhs_arr) np.testing.assert_almost_equal(result, out_ser.to_numpy()) diff --git a/python/cudf/cudf/tests/test_udf_masked_ops.py b/python/cudf/cudf/tests/test_udf_masked_ops.py index 36750adf6ee..b68a7562b6b 100644 --- a/python/cudf/cudf/tests/test_udf_masked_ops.py +++ b/python/cudf/cudf/tests/test_udf_masked_ops.py @@ -645,7 +645,8 @@ def test_masked_udf_caching(): data = cudf.Series([1, 2, 3]) expect = data**2 - got = data.applymap(lambda x: x**2) + with pytest.warns(FutureWarning): + got = data.applymap(lambda x: x**2) assert_eq(expect, got, check_dtype=False) @@ -653,7 +654,8 @@ def test_masked_udf_caching(): # it does not result in a cache hit expect = data**3 - got = data.applymap(lambda x: x**3) + with pytest.warns(FutureWarning): + got = data.applymap(lambda x: x**3) assert_eq(expect, got, check_dtype=False) # make sure we get a hit when reapplying