diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 287fd3796f4..e667c4a1e58 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -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 diff --git a/python/cudf/cudf/tests/test_setitem.py b/python/cudf/cudf/tests/test_setitem.py index 1fce7853fdf..fd3f2732556 100644 --- a/python/cudf/cudf/tests/test_setitem.py +++ b/python/cudf/cudf/tests/test_setitem.py @@ -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