Skip to content

Commit

Permalink
Fix null handling when boolean dtype is passed (#9691)
Browse files Browse the repository at this point in the history
Fixes: #9642 

This PR fixes issue where null values being treated as `False` when `boolean` dtype was being passed to the `Series` constructor.

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

Approvers:
  - Ashwin Srinath (https://github.com/shwina)

URL: #9691
  • Loading branch information
galipremsagar authored Nov 16, 2021
1 parent c667518 commit c3bcc8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,11 @@ def as_column(
return cudf.core.column.Decimal32Column.from_arrow(
data
)
if is_bool_dtype(dtype):
# Need this special case handling for bool dtypes,
# since 'boolean' & 'pd.BooleanDtype' are not
# understood by np.dtype below.
dtype = "bool"
np_type = np.dtype(dtype).type
pa_type = np_to_pa_dtype(np.dtype(dtype))
data = as_column(
Expand Down
11 changes: 11 additions & 0 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,3 +1335,14 @@ def test_equals_names(lhs, rhs):
expect = lhs.to_pandas().equals(rhs.to_pandas())

assert_eq(expect, got)


@pytest.mark.parametrize(
"data", [[True, False, None, True, False], [None, None], []]
)
@pytest.mark.parametrize("bool_dtype", ["bool", "boolean", pd.BooleanDtype()])
def test_nullable_bool_dtype_series(data, bool_dtype):
psr = pd.Series(data, dtype=pd.BooleanDtype())
gsr = cudf.Series(data, dtype=bool_dtype)

assert_eq(psr, gsr.to_pandas(nullable=True))

0 comments on commit c3bcc8d

Please sign in to comment.