From d684ae0e80d179d4d711c00278d00b5f66625303 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 14 Aug 2024 12:36:51 -1000 Subject: [PATCH] Raise NotImplementedError for Series.rename that's not a scalar (#16525) xref https://github.com/rapidsai/cudf/issues/16507 Raising a `NotImplementedError` gives a chance for this work in `cudf.pandas` Authors: - Matthew Roeschke (https://github.com/mroeschke) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) URL: https://github.com/rapidsai/cudf/pull/16525 --- python/cudf/cudf/core/series.py | 4 ++++ python/cudf/cudf/tests/test_series.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index 53675d339ac..822b966364f 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -3589,6 +3589,10 @@ def rename( raise NotImplementedError("level is currently not supported.") if errors != "ignore": raise NotImplementedError("errors is currently not supported.") + if not is_scalar(index): + raise NotImplementedError( + ".rename does not currently support relabeling the index." + ) out_data = self._data.copy(deep=copy) return Series._from_data(out_data, self.index, name=index) diff --git a/python/cudf/cudf/tests/test_series.py b/python/cudf/cudf/tests/test_series.py index 6a1887afb1f..c7aea563535 100644 --- a/python/cudf/cudf/tests/test_series.py +++ b/python/cudf/cudf/tests/test_series.py @@ -2289,6 +2289,13 @@ def test_series_rename(initial_name, name): assert_eq(actual, expected) +@pytest.mark.parametrize("index", [lambda x: x * 2, {1: 2}]) +def test_rename_index_not_supported(index): + ser = cudf.Series(range(2)) + with pytest.raises(NotImplementedError): + ser.rename(index=index) + + @pytest.mark.parametrize( "data", [