diff --git a/python/cudf/cudf/core/tools/datetimes.py b/python/cudf/cudf/core/tools/datetimes.py index f7dea65a401..7c4b9810df2 100644 --- a/python/cudf/cudf/core/tools/datetimes.py +++ b/python/cudf/cudf/core/tools/datetimes.py @@ -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. diff --git a/python/cudf/cudf/tests/test_datetime.py b/python/cudf/cudf/tests/test_datetime.py index 4c4657ccba1..abcc057f823 100644 --- a/python/cudf/cudf/tests/test_datetime.py +++ b/python/cudf/cudf/tests/test_datetime.py @@ -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)