Skip to content

Commit

Permalink
Raise error when pd.periodIndex is passed to the column constructor (
Browse files Browse the repository at this point in the history
…#4)

Fixes: #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.
  • Loading branch information
galipremsagar authored Oct 2, 2023
1 parent 3d587b3 commit cfe61de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit cfe61de

Please sign in to comment.