From d15d470e526de205bed8808a9c15d0a4d7642667 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Mon, 26 Aug 2024 12:03:41 -0500 Subject: [PATCH] Preserve Series name in duplicated method. (#16655) Closes #16654. Authors: - Bradley Dice (https://github.com/bdice) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) - Matthew Roeschke (https://github.com/mroeschke) URL: https://github.com/rapidsai/cudf/pull/16655 --- python/cudf/cudf/core/indexed_frame.py | 4 +++- python/cudf/cudf/tests/test_series.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/cudf/cudf/core/indexed_frame.py b/python/cudf/cudf/core/indexed_frame.py index 60253b9ae5d..ad6aa56d472 100644 --- a/python/cudf/cudf/core/indexed_frame.py +++ b/python/cudf/cudf/core/indexed_frame.py @@ -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( @@ -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: diff --git a/python/cudf/cudf/tests/test_series.py b/python/cudf/cudf/tests/test_series.py index c7aea563535..8d673e23ab2 100644 --- a/python/cudf/cudf/tests/test_series.py +++ b/python/cudf/cudf/tests/test_series.py @@ -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))