From 11e58831dca71d52fe5880079c7d206b135f67e7 Mon Sep 17 00:00:00 2001 From: Jonathan Shi Date: Thu, 12 Sep 2024 14:00:43 -0700 Subject: [PATCH 1/2] FIX-#7375: Fix Series.duplicated dropping name Signed-off-by: Jonathan Shi --- modin/pandas/series.py | 6 +++++- modin/tests/pandas/test_series.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modin/pandas/series.py b/modin/pandas/series.py index d18a0bec778..006981966c7 100644 --- a/modin/pandas/series.py +++ b/modin/pandas/series.py @@ -1022,7 +1022,11 @@ def duplicated(self, keep="first") -> Series: # noqa: PR01, RT01, D200 """ Indicate duplicate Series values. """ - return self.to_frame().duplicated(keep=keep) + name = self.name + result = self.to_frame().duplicated(keep=keep) + # DataFrame.duplicated drops the name, so we need to manually restore it + result.name = name + return result def eq( self, other, level=None, fill_value=None, axis=0 diff --git a/modin/tests/pandas/test_series.py b/modin/tests/pandas/test_series.py index 9dd8b98aac3..b283a7a1ede 100644 --- a/modin/tests/pandas/test_series.py +++ b/modin/tests/pandas/test_series.py @@ -1942,6 +1942,12 @@ def test_duplicated(data, keep): df_equals(modin_result, pandas_series.duplicated(keep=keep)) +def test_duplicated_keeps_name_issue_7375(): + # Ensure that the name property of a series is preserved across duplicated + modin_series, pandas_series = create_test_series([1, 2, 3, 1], name="a") + df_equals(modin_series.duplicated(), pandas_series.duplicated()) + + @pytest.mark.parametrize("data", test_data_values, ids=test_data_keys) def test_empty(data): modin_series, pandas_series = create_test_series(data) From cf4dd6df5961cd1540df70b3d1c338c382a6bc45 Mon Sep 17 00:00:00 2001 From: Jonathan Shi Date: Fri, 13 Sep 2024 13:42:20 -0700 Subject: [PATCH 2/2] Update modin/pandas/series.py Co-authored-by: Anatoly Myachev --- modin/pandas/series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modin/pandas/series.py b/modin/pandas/series.py index 006981966c7..00083200762 100644 --- a/modin/pandas/series.py +++ b/modin/pandas/series.py @@ -1025,7 +1025,8 @@ def duplicated(self, keep="first") -> Series: # noqa: PR01, RT01, D200 name = self.name result = self.to_frame().duplicated(keep=keep) # DataFrame.duplicated drops the name, so we need to manually restore it - result.name = name + if name is not None: + result.name = name return result def eq(