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.hash_encode. #9457

Merged
merged 3 commits into from
Oct 19, 2021
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
10 changes: 10 additions & 0 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,9 @@ def hash_values(self, method="murmur3"):
def hash_encode(self, stop, use_name=False):
"""Encode column values as ints in [0, stop) using hash function.
This method is deprecated. Replace ``series.hash_encode(stop,
use_name=False)`` with ``series.hash_values(method="murmur3") % stop``.
Parameters
----------
stop : int
Expand Down Expand Up @@ -3544,6 +3547,13 @@ def hash_encode(self, stop, use_name=False):
2 76
dtype: int32
"""
warnings.warn(
"The `hash_encode` method will be removed in a future cuDF "
"release. Replace `series.hash_encode(stop, use_name=False)` "
'with `series.hash_values(method="murmur3") % stop`.',
FutureWarning,
)

if not stop > 0:
raise ValueError("stop must be a positive integer.")

Expand Down
14 changes: 10 additions & 4 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2218,24 +2218,30 @@ def test_series_hash_encode(nrows):
s = cudf.Series(data, name=1)
num_features = 1000

encoded_series = s.hash_encode(num_features)
with pytest.warns(FutureWarning):
encoded_series = s.hash_encode(num_features)
assert isinstance(encoded_series, cudf.Series)
enc_arr = encoded_series.to_numpy()
assert np.all(enc_arr >= 0)
assert np.max(enc_arr) < num_features

enc_with_name_arr = s.hash_encode(num_features, use_name=True).to_numpy()
with pytest.warns(FutureWarning):
enc_with_name_arr = s.hash_encode(
num_features, use_name=True
).to_numpy()
assert enc_with_name_arr[0] != enc_arr[0]


def test_series_hash_encode_reproducible_results():
# Regression test to ensure that hash_encode outputs are reproducible
data = cudf.Series([0, 1, 2])
hash_result = data.hash_encode(stop=2 ** 16, use_name=False)
with pytest.warns(FutureWarning):
hash_result = data.hash_encode(stop=2 ** 16, use_name=False)
expected_result = cudf.Series([42165, 55037, 7341])
assert_eq(hash_result, expected_result)

hash_result_with_name = data.hash_encode(stop=2 ** 16, use_name=True)
with pytest.warns(FutureWarning):
hash_result_with_name = data.hash_encode(stop=2 ** 16, use_name=True)
expected_result_with_name = cudf.Series([36137, 39649, 58673])
assert_eq(hash_result_with_name, expected_result_with_name)

Expand Down