From cfe61de0d6ec2cb2641d12005c6b1e211505fb12 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Mon, 2 Oct 2023 12:32:16 -0500 Subject: [PATCH] Raise error when `pd.periodIndex` is passed to the column constructor (#4) Fixes: rapidsai/cudf#14148 This PR resolves a RunTimeError by raising when a pd.PeriodIndex is passed to the column constructor, the reason being there is no cudf.PeriodIndex implemented yet. --- python/cudf/cudf/core/column/column.py | 10 ++++++++++ python/cudf/cudf/tests/test_index.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index e171287d694..a61b2e1a463 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -2056,6 +2056,10 @@ def as_column( data = as_column( cupy.asarray(arbitrary), nan_as_null=nan_as_null, dtype=dtype ) + elif isinstance(arbitrary.dtype, pd.PeriodDtype): + raise NotImplementedError( + "cuDF does not yet support `PeriodDtype`" + ) else: pyarrow_array = pa.array(arbitrary, from_pandas=nan_as_null) if arbitrary.dtype == cudf.dtype("object") and cudf.dtype( @@ -2286,6 +2290,12 @@ def as_column( raise NotImplementedError( "cuDF does not yet support timezone-aware datetimes" ) + elif isinstance( + arbitrary, (pd.core.arrays.period.PeriodArray, pd.PeriodIndex) + ): + raise NotImplementedError( + f"cuDF does not yet support {type(arbitrary).__name__}" + ) elif ( cudf.get_option("mode.pandas_compatible") and isinstance(arbitrary, (pd.DatetimeIndex, pd.TimedeltaIndex)) diff --git a/python/cudf/cudf/tests/test_index.py b/python/cudf/cudf/tests/test_index.py index 29232f63e90..d326f50e1cc 100644 --- a/python/cudf/cudf/tests/test_index.py +++ b/python/cudf/cudf/tests/test_index.py @@ -2804,3 +2804,17 @@ def test_index_to_frame(data, data_name, index, name): actual = gidx.to_frame(index=index, name=name) assert_eq(expected, actual) + + +def test_period_index_error(): + pidx = pd.PeriodIndex(year=[2000, 2002], quarter=[1, 3]) + with pytest.raises(NotImplementedError): + cudf.from_pandas(pidx) + with pytest.raises(NotImplementedError): + cudf.Index(pidx) + with pytest.raises(NotImplementedError): + cudf.Series(pidx) + with pytest.raises(NotImplementedError): + cudf.Series(pd.Series(pidx)) + with pytest.raises(NotImplementedError): + cudf.Series(pd.array(pidx))