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

[REVIEW] Fix vectorizer tests by restoring sort behavior in groupby #3416

Merged
Merged
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
17 changes: 10 additions & 7 deletions python/cuml/feature_extraction/_vectorizers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -153,7 +153,8 @@ def get_char_ngrams(self, ngram_size, str_series, doc_id_sr):
'ngram_count': tokens.str.len() - (ngram_size - 1)
})
del tokens
ngram_count = doc_id_df.groupby('doc_id').sum()['ngram_count']
ngram_count = doc_id_df.groupby('doc_id',
sort=True).sum()['ngram_count']
return ngram_sr, ngram_count, token_count

if ngram_size == 1:
Expand Down Expand Up @@ -292,7 +293,7 @@ def _document_frequency(X):
"""
doc_freq = (
X[["token", "doc_id"]]
.groupby(["token"])
.groupby(["token"], sort=True)
.count()
)
return doc_freq["doc_id"].values
Expand All @@ -304,7 +305,7 @@ def _term_frequency(X):
"""
term_freq = (
X[["token", "count"]]
.groupby(["token"])
.groupby(["token"], sort=True)
.sum()
)
return term_freq["count"].values
Expand Down Expand Up @@ -437,7 +438,7 @@ def _count_vocab(self, tokenized_df):
# Count of each token in each document
count_df = (
tokenized_df[["doc_id", "token"]]
.groupby(["doc_id", "token"])
.groupby(["doc_id", "token"], sort=True)
.size()
.reset_index()
.rename({0: "count"}, axis=1)
Expand Down Expand Up @@ -851,12 +852,14 @@ def _count_hash(self, tokenized_df):
tokenized_df["value"] = ((tokenized_df["token"] >= 0) * 2) - 1
tokenized_df["token"] = tokenized_df["token"].abs() %\
self.n_features
count_ser = tokenized_df.groupby(["doc_id", "token"]).value.sum()
count_ser = tokenized_df.groupby(["doc_id", "token"],
sort=True).value.sum()
count_ser.name = "count"
else:
tokenized_df["token"] = tokenized_df["token"].abs() %\
self.n_features
count_ser = tokenized_df.groupby(["doc_id", "token"]).size()
count_ser = tokenized_df.groupby(["doc_id", "token"],
sort=True).size()
count_ser.name = "count"

count_df = count_ser.reset_index(drop=False)
Expand Down