Skip to content

Commit

Permalink
Raise an error when timezone subtypes are encountered in `pd.Interval…
Browse files Browse the repository at this point in the history
…Dtype` (#14006)

closes #14004 

This PR raises an error when an `IntervalIndex` contains a timezone-aware sub-type so that we don't go into infinite recursion.

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

Approvers:
  - Matthew Roeschke (https://github.com/mroeschke)

URL: #14006
  • Loading branch information
galipremsagar authored Aug 30, 2023
1 parent 04ee729 commit c1b7931
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2261,8 +2261,12 @@ def as_column(
data = ColumnBase.from_scalar(arbitrary, length if length else 1)
elif isinstance(arbitrary, pd.core.arrays.masked.BaseMaskedArray):
data = as_column(pa.Array.from_pandas(arbitrary), dtype=dtype)
elif isinstance(arbitrary, pd.DatetimeIndex) and isinstance(
arbitrary.dtype, pd.DatetimeTZDtype
elif (
isinstance(arbitrary, pd.DatetimeIndex)
and isinstance(arbitrary.dtype, pd.DatetimeTZDtype)
) or (
isinstance(arbitrary, pd.IntervalIndex)
and is_datetime64tz_dtype(arbitrary.dtype.subtype)
):
raise NotImplementedError(
"cuDF does not yet support timezone-aware datetimes"
Expand Down
16 changes: 16 additions & 0 deletions python/cudf/cudf/tests/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,19 @@ def test_interval_index_unique():
actual = gi.unique()

assert_eq(expected, actual)


@pytest.mark.parametrize("tz", ["US/Eastern", None])
def test_interval_with_datetime(tz):
dti = pd.date_range(
start=pd.Timestamp("20180101", tz=tz),
end=pd.Timestamp("20181231", tz=tz),
freq="M",
)
pidx = pd.IntervalIndex.from_breaks(dti)
if tz is None:
gidx = cudf.from_pandas(pidx)
assert_eq(pidx, gidx)
else:
with pytest.raises(NotImplementedError):
cudf.from_pandas(pidx)

0 comments on commit c1b7931

Please sign in to comment.