Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable creation of DatetimeIndex when freq is passed to cudf.date_range #13890

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/cudf/cudf/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ def date_range(
arr = cp.linspace(start=start, stop=end, num=periods)
result = cudf.core.column.as_column(arr).astype("datetime64[ns]")
return cudf.DatetimeIndex._from_data({name: result})
elif cudf.get_option("mode.pandas_compatible"):
raise NotImplementedError(
"`DatetimeIndex` with `freq` cannot be constructed."
)

# The code logic below assumes `freq` is defined. It is first normalized
# into `DateOffset` for further computation with timestamps.
Expand Down
13 changes: 13 additions & 0 deletions python/cudf/cudf/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2133,3 +2133,16 @@ def test_datetime_series_cmpops_pandas_compatibility(data1, data2, op):
def test_datetime_getitem_na():
s = cudf.Series([1, 2, None, 3], dtype="datetime64[ns]")
assert s[2] is cudf.NaT


def test_daterange_pandas_compatibility():
with cudf.option_context("mode.pandas_compatible", True):
with pytest.raises(NotImplementedError):
cudf.date_range("20010101", "20020215", freq="400h", name="times")
expected = pd.date_range(
"2010-01-01", "2010-02-01", periods=10, name="times"
)
actual = cudf.date_range(
"2010-01-01", "2010-02-01", periods=10, name="times"
)
assert_eq(expected, actual)