diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 48c1f49e6ea..30b6c307fbd 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -7953,7 +7953,7 @@ def _setitem_with_dataframe( "Number of Input Columns must be same replacement Dataframe" ) - if not input_df.index.equals(replace_df.index): + if len(input_df) != 0 and not input_df.index.equals(replace_df.index): replace_df = replace_df.reindex(input_df.index) for col_1, col_2 in zip(input_cols, replace_df.columns): diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index f068d02d575..810eabdf699 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -1070,6 +1070,13 @@ def test_dataframe_setitem_index_len1(): np.testing.assert_equal(gdf.b.to_array(), [0]) +def test_empty_dataframe_setitem_df(): + gdf1 = cudf.DataFrame() + gdf2 = cudf.DataFrame({"a": [1, 2, 3, 4, 5]}) + gdf1["a"] = gdf2["a"] + assert_eq(gdf1, gdf2) + + def test_assign(): gdf = cudf.DataFrame({"x": [1, 2, 3]}) gdf2 = gdf.assign(y=gdf.x + 1)