From 74d6af097ff26fb4f7ff11a99c8f7bf78b2ad2be Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:36:58 -0700 Subject: [PATCH 1/2] Support IntervalDtype in cudf.from_pandas --- python/cudf/cudf/core/dataframe.py | 2 ++ python/cudf/cudf/tests/test_interval.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index e1b6cc45dd3..eed7e4ac8ba 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -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, " diff --git a/python/cudf/cudf/tests/test_interval.py b/python/cudf/cudf/tests/test_interval.py index 7b923af1f75..013f4439ad5 100644 --- a/python/cudf/cudf/tests/test_interval.py +++ b/python/cudf/cudf/tests/test_interval.py @@ -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) From 6f2993db27a7766cc3eaefc01c38a6622f8f3986 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:05:35 -0700 Subject: [PATCH 2/2] Better exception message --- python/cudf/cudf/core/dataframe.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index eed7e4ac8ba..7438b0237d5 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -8076,9 +8076,7 @@ def from_pandas(obj, nan_as_null=no_default): 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__}" )