From 7331922486c0e5f1e6a765efa8063aa7603c7add Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Thu, 7 Sep 2023 09:59:52 -0500 Subject: [PATCH] Raise `NotImplementedError` for `MultiIndex.to_series` (#14049) Fixes #14035 This PR raises an error for `MultiIndex.to_series` because we cannot store `tuple` type columns in `cudf`. Authors: - GALI PREM SAGAR (https://github.com/galipremsagar) Approvers: - Lawrence Mitchell (https://github.com/wence-) URL: https://github.com/rapidsai/cudf/pull/14049 --- python/cudf/cudf/core/multiindex.py | 6 ++++++ python/cudf/cudf/tests/test_multiindex.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/python/cudf/cudf/core/multiindex.py b/python/cudf/cudf/core/multiindex.py index 12da69740d8..bc6726879c1 100644 --- a/python/cudf/cudf/core/multiindex.py +++ b/python/cudf/cudf/core/multiindex.py @@ -219,6 +219,12 @@ def names(self, value): ) self._names = pd.core.indexes.frozen.FrozenList(value) + @_cudf_nvtx_annotate + def to_series(self, index=None, name=None): + raise NotImplementedError( + "MultiIndex.to_series isn't implemented yet." + ) + @_cudf_nvtx_annotate def astype(self, dtype, copy: bool = True): if not is_object_dtype(dtype): diff --git a/python/cudf/cudf/tests/test_multiindex.py b/python/cudf/cudf/tests/test_multiindex.py index 56bd7d709b7..3c843ace0a8 100644 --- a/python/cudf/cudf/tests/test_multiindex.py +++ b/python/cudf/cudf/tests/test_multiindex.py @@ -1920,3 +1920,9 @@ def test_multiindex_sort_index_partial(levels): expect = df.sort_index(level=levels, sort_remaining=True) got = cdf.sort_index(level=levels, sort_remaining=True) assert_eq(expect, got) + + +def test_multiindex_to_series_error(): + midx = cudf.MultiIndex.from_tuples([("a", "b")]) + with pytest.raises(NotImplementedError): + midx.to_series()