Skip to content

Commit

Permalink
Fix an issue where creation of categorical from scalar fails
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Apr 5, 2024
1 parent 7c69e66 commit 6fe7ed7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,11 @@ def as_column(
if dtype is not None:
data = data.astype(dtype)

elif is_scalar(arbitrary) and not isinstance(arbitrary, memoryview):
elif (
is_scalar(arbitrary)
and not isinstance(arbitrary, memoryview)
and not _is_categorical_dtype(dtype)
):
if length is None:
length = 1
elif length < 0:
Expand Down
8 changes: 8 additions & 0 deletions python/cudf/cudf/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,3 +846,11 @@ def test_empty_series_category_cast(ordered):

assert_eq(expected, actual)
assert_eq(expected.dtype.ordered, actual.dtype.ordered)


@pytest.mark.parametrize("scalar", [1, "a", None, 10.2])
def test_cat_from_scalar(scalar):
ps = pd.Series(scalar, dtype="category")
gs = cudf.Series(scalar, dtype="category")

assert_eq(ps, gs)

0 comments on commit 6fe7ed7

Please sign in to comment.