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

Preserve Series name in duplicated method. #16655

Merged
merged 2 commits into from
Aug 26, 2024
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
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3198,8 +3198,10 @@ def duplicated(self, subset=None, keep="first"):
"""
subset = self._preprocess_subset(subset)

name = None
if isinstance(self, cudf.Series):
columns = [self._column]
name = self.name
else:
columns = [self._data[n] for n in subset]
distinct = libcudf.stream_compaction.distinct_indices(
Expand All @@ -3211,7 +3213,7 @@ def duplicated(self, subset=None, keep="first"):
[as_column(True, length=len(self), dtype=bool)],
bounds_check=False,
)[0]
return cudf.Series._from_column(result, index=self.index)
return cudf.Series._from_column(result, index=self.index, name=name)

@_performance_tracking
def _empty_like(self, keep_index=True) -> Self:
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2115,8 +2115,9 @@ def test_series_hasnans(data):
],
)
@pytest.mark.parametrize("keep", ["first", "last", False])
def test_series_duplicated(data, index, keep):
gs = cudf.Series(data, index=index)
@pytest.mark.parametrize("name", [None, "a"])
def test_series_duplicated(data, index, keep, name):
gs = cudf.Series(data, index=index, name=name)
ps = gs.to_pandas()

assert_eq(gs.duplicated(keep=keep), ps.duplicated(keep=keep))
Expand Down
Loading