Skip to content

Commit

Permalink
Preserve Series name in duplicated method. (#16655)
Browse files Browse the repository at this point in the history
Closes #16654.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #16655
  • Loading branch information
bdice authored Aug 26, 2024
1 parent a250391 commit d15d470
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit d15d470

Please sign in to comment.