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

Support IntervalDtype in cudf.from_pandas #16014

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8072,6 +8072,8 @@ 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, "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this error string is increasingly out of date (it doesn't mention categoricaldtype and now intervaldtype). Should we reword the be less specific?

f"from_pandas unsupported for object of type {type(obj)}"

perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Changed to this

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)
Loading