Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Series.applymap #10497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions python/cudf/cudf/tests/test_applymap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2021, NVIDIA CORPORATION.
# Copyright (c) 2018-2022, NVIDIA CORPORATION.

from itertools import product
from math import floor
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
6 changes: 4 additions & 2 deletions python/cudf/cudf/tests/test_udf_masked_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,17 @@ 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)

# update the constant value being used and make sure
# 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
Expand Down