From 6004032762fea55606c18f267a94ccf5cd60633f Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Tue, 12 Apr 2022 15:35:24 +0800 Subject: [PATCH 1/2] Add a test for Series.name preserved in ser.mode --- pandas/tests/test_algos.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 7c16d13e59d3a..f656183739a48 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -2282,6 +2282,11 @@ def test_index(self): # algos.mode expects Arraylike, does *not* unwrap TimedeltaIndex algos.mode(idx) + def test_ser_mode_with_name(self): + ser = Series([1, 2, 3]) + ser.name = "foo" + tm.assert_equal(ser.mode().name, "foo") + class TestDiff: @pytest.mark.parametrize("dtype", ["M8[ns]", "m8[ns]"]) From c94a59d48d001f3074b50e61ed1c10fdcf90adca Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Wed, 13 Apr 2022 18:03:46 +0800 Subject: [PATCH 2/2] Address comments --- pandas/tests/test_algos.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index f656183739a48..2d73b8e91e831 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -2283,9 +2283,11 @@ def test_index(self): algos.mode(idx) def test_ser_mode_with_name(self): - ser = Series([1, 2, 3]) - ser.name = "foo" - tm.assert_equal(ser.mode().name, "foo") + # GH 46737 + ser = Series([1, 1, 3], name="foo") + result = ser.mode() + expected = Series([1], name="foo") + tm.assert_series_equal(result, expected) class TestDiff: