Skip to content

Commit

Permalink
Disable construction of Index when freq is set in pandas-compatibil…
Browse files Browse the repository at this point in the history
…ity mode (#13857)

This PR raises an error when a `cudf` column/series/Index is being constructed using a pandas Index that has a `freq` set. This error is raised only in pandas-compatibility mode, because we will have to switch to `cudf.date_range` everywhere in the code base and examples, and `cudf.date_range` still isn't at a full feature parity with `pd.date_range`.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Ashwin Srinath (https://github.com/shwina)

URL: #13857
  • Loading branch information
galipremsagar authored Aug 12, 2023
1 parent bf9b110 commit 989c411
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,12 @@ def as_column(
raise NotImplementedError(
"cuDF does not yet support timezone-aware datetimes"
)
elif (
cudf.get_option("mode.pandas_compatible")
and isinstance(arbitrary, (pd.DatetimeIndex, pd.TimedeltaIndex))
and arbitrary.freq is not None
):
raise NotImplementedError("freq is not implemented yet")
else:
try:
data = as_column(
Expand Down
8 changes: 8 additions & 0 deletions python/cudf/cudf/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2670,3 +2670,11 @@ def test_index_mixed_dtype_error(data):
pi = pd.Index(data)
with pytest.raises(TypeError):
cudf.Index(pi)


@pytest.mark.parametrize("cls", [pd.DatetimeIndex, pd.TimedeltaIndex])
def test_index_date_duration_freq_error(cls):
s = cls([1, 2, 3], freq="infer")
with cudf.option_context("mode.pandas_compatible", True):
with pytest.raises(NotImplementedError):
cudf.Index(s)

0 comments on commit 989c411

Please sign in to comment.