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

Fix failures when performing binary operations on DataFrames with empty columns #8452

Merged
merged 6 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,16 @@ def _binaryop(
if isinstance(other, cudf.DataFrame):
return NotImplemented

# Ignore empty object columns when performing arithmetic operations
if (
self.dtype == "object"
and self.isnull().all()
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
and fill_value is None
and fn
in ("add", "sub", "mul", "mod", "pow", "truediv", "floordiv")
):
return self

if isinstance(other, Series):
if (
not can_reindex
Expand Down
16 changes: 16 additions & 0 deletions python/cudf/cudf/tests/test_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2870,3 +2870,19 @@ def set_null_cases(column_l, column_r, case):
)
def test_null_equals_columnops(lcol, rcol, ans, case):
assert lcol._null_equals(rcol).all() == ans


@pytest.mark.parametrize("binop", _binops)
@pytest.mark.parametrize("data", [None, [-9, 7], [5, -2], [12, 18]])
@pytest.mark.parametrize("scalar", [1, 3, 12, np.nan])
def test_empty_column(binop, data, scalar):
gdf = cudf.DataFrame(columns=["a", "b"])
if data is not None:
gdf["a"] = data

pdf = gdf.to_pandas()

got = binop(gdf, scalar)
expected = binop(pdf, scalar)

utils.assert_eq(expected, got)