Skip to content

Commit

Permalink
Inserting a cudf.NA into a DataFrame (#8923)
Browse files Browse the repository at this point in the history
Addressing #8922 - just have to check if it's a `cudf.NA` and set to `None` if necessary.

Authors:
  - Sarah Yurick (https://github.com/sarahyurick)

Approvers:
  - https://github.com/brandon-b-miller
  - Ram (Ramakrishna Prabhu) (https://github.com/rgsl888prabhu)

URL: #8923
  • Loading branch information
sarahyurick authored Aug 2, 2021
1 parent 8c9d2be commit b17024e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 12 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5054,6 +5054,18 @@ def test_insert(data):
assert_eq(pdf, gdf)


@pytest.mark.parametrize(
"data", [{"A": [1, 2, 3], "B": ["a", "b", "c"]}],
)
def test_insert_NA(data):
pdf = pd.DataFrame.from_dict(data)
gdf = cudf.DataFrame.from_pandas(pdf)

pdf["C"] = pd.NA
gdf["C"] = cudf.NA
assert_eq(pdf, gdf)


def test_cov():
gdf = cudf.datasets.randomdata(10)
pdf = gdf.to_pandas()
Expand Down
5 changes: 1 addition & 4 deletions python/cudf/cudf/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ def scalar_broadcast_to(scalar, size, dtype=None):
if isinstance(size, (tuple, list)):
size = size[0]

if scalar is None or (
isinstance(scalar, (np.datetime64, np.timedelta64))
and np.isnat(scalar)
):
if cudf._lib.scalar._is_null_host_scalar(scalar):
if dtype is None:
dtype = "object"
return column.column_empty(size, dtype=dtype, masked=True)
Expand Down

0 comments on commit b17024e

Please sign in to comment.