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

Don't reindex an new value on setitem if the original dataframe was empty #8026

Merged
merged 3 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 1 deletion python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down