Skip to content

Commit

Permalink
Support IntervalDtype in cudf.from_pandas (#16014)
Browse files Browse the repository at this point in the history
Noticed while running the pandas test suite against `cudf.pandas`

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

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Lawrence Mitchell (https://github.com/wence-)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #16014
  • Loading branch information
mroeschke authored Jun 13, 2024
1 parent 3f8f214 commit 31d909b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8072,11 +8072,11 @@ def from_pandas(obj, nan_as_null=no_default):
return cudf.Index.from_pandas(obj, nan_as_null=nan_as_null)
elif isinstance(obj, pd.CategoricalDtype):
return cudf.CategoricalDtype.from_pandas(obj)
elif isinstance(obj, pd.IntervalDtype):
return cudf.IntervalDtype.from_pandas(obj)
else:
raise TypeError(
"from_pandas only accepts Pandas Dataframes, Series, "
"Index, RangeIndex and MultiIndex objects. "
"Got %s" % type(obj)
f"from_pandas unsupported for object of type {type(obj).__name__}"
)


Expand Down
7 changes: 7 additions & 0 deletions python/cudf/cudf/tests/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,10 @@ def test_interval_with_datetime(tz, box):
else:
with pytest.raises(NotImplementedError):
cudf.from_pandas(pobj)


def test_from_pandas_intervaldtype():
dtype = pd.IntervalDtype("int64", closed="left")
result = cudf.from_pandas(dtype)
expected = cudf.IntervalDtype("int64", closed="left")
assert_eq(result, expected)

0 comments on commit 31d909b

Please sign in to comment.