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

Inserting a cudf.NA into a DataFrame #8923

Merged
merged 3 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -3079,6 +3079,8 @@ def insert(self, loc, name, value):
)

if _is_scalar_or_zero_d_array(value):
if value is cudf.NA:
value = None
sarahyurick marked this conversation as resolved.
Show resolved Hide resolved
value = utils.scalar_broadcast_to(value, len(self))

if len(self) == 0:
Expand Down
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