Skip to content

Commit

Permalink
Fix issue with column and scalar re-assignment (#10377)
Browse files Browse the repository at this point in the history
Fixes: #10305  This PR fixes issues where the `scalar` that is being assigned was being type-casted to the column's type. Added test coverage for the same.

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

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #10377
  • Loading branch information
galipremsagar authored Mar 2, 2022
1 parent fbac0ac commit 6bcfc10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,9 @@ def __setitem__(self, arg, value):
allow_non_unique=True,
)
if is_scalar(value):
self._data[arg][:] = value
self._data[arg] = utils.scalar_broadcast_to(
value, len(self)
)
else:
value = as_column(value)
self._data[arg] = value
Expand Down
9 changes: 7 additions & 2 deletions python/cudf/cudf/tests/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ def test_dataframe_setitem_scaler_bool():
assert_eq(df, gdf)


@pytest.mark.parametrize("df", [pd.DataFrame({"a": [1, 2, 3]})])
@pytest.mark.parametrize(
"df",
[pd.DataFrame({"a": [1, 2, 3]}), pd.DataFrame({"a": ["x", "y", "z"]})],
)
@pytest.mark.parametrize("arg", [["a"], "a", "b"])
@pytest.mark.parametrize("value", [-10, pd.DataFrame({"a": [-1, -2, -3]})])
@pytest.mark.parametrize(
"value", [-10, pd.DataFrame({"a": [-1, -2, -3]}), "abc"]
)
def test_dataframe_setitem_columns(df, arg, value):
gdf = cudf.from_pandas(df)
cudf_replace_value = value
Expand Down

0 comments on commit 6bcfc10

Please sign in to comment.