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 Series/Dataframe Mixed Arithmetic #7491

Merged
Show file tree
Hide file tree
Changes from 13 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
8 changes: 2 additions & 6 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,11 +1455,7 @@ def fallback(col, fn):
else:
if col not in df_cols:
r_opr = other_cols[col]
l_opr = Series(
column_empty(
len(self), masked=True, dtype=other.dtype
)
)
l_opr = Series(as_column(np.nan, length=len(self)))
if col not in other_cols_keys:
r_opr = None
l_opr = self[col]
Expand Down Expand Up @@ -2135,7 +2131,7 @@ def rpow(self, other, axis="columns", level=None, fill_value=None):
return self._apply_op("rpow", other, fill_value)

def __rpow__(self, other):
return self._apply_op("__pow__", other)
return self._apply_op("__rpow__", other)

def floordiv(self, other, axis="columns", level=None, fill_value=None):
"""
Expand Down
4 changes: 1 addition & 3 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,7 @@ def _binaryop(self, other, fn, fill_value=None, reflect=False):
If ``reflect`` is ``True``, swap the order of the operands.
"""
if isinstance(other, cudf.DataFrame):
# TODO: fn is not the same as arg expected by _apply_op
# e.g. for fn = 'and', _apply_op equivalent is '__and__'
return other._apply_op(self, fn)
return NotImplemented

result_name = utils.get_result_name(self, other)
if isinstance(other, Series):
Expand Down
41 changes: 22 additions & 19 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4987,13 +4987,13 @@ def test_cov_nans():
@pytest.mark.parametrize(
"gsr",
[
cudf.Series([1, 2, 3]),
cudf.Series([1, 2, 3], index=["a", "b", "c"]),
cudf.Series([1, 2, 3], index=["a", "b", "d"]),
cudf.Series([1, 2], index=["a", "b"]),
cudf.Series([1, 2, 3], index=cudf.core.index.RangeIndex(0, 3)),
cudf.Series([4, 2, 3]),
cudf.Series([4, 2, 3], index=["a", "b", "c"]),
cudf.Series([4, 2, 3], index=["a", "b", "d"]),
cudf.Series([4, 2], index=["a", "b"]),
cudf.Series([4, 2, 3], index=cudf.core.index.RangeIndex(0, 3)),
pytest.param(
cudf.Series([1, 2, 3, 4, 5], index=["a", "b", "d", "0", "12"]),
cudf.Series([4, 2, 3, 4, 5], index=["a", "b", "d", "0", "12"]),
marks=pytest.mark.xfail,
),
],
Expand All @@ -5008,30 +5008,33 @@ def test_cov_nans():
operator.truediv,
operator.mod,
operator.pow,
operator.eq,
operator.lt,
operator.le,
operator.gt,
operator.ge,
operator.ne,
# TODO: Remove XFAILs after PR is merged
pytest.param(operator.eq, marks=pytest.mark.xfail()),
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
pytest.param(operator.lt, marks=pytest.mark.xfail()),
pytest.param(operator.le, marks=pytest.mark.xfail()),
pytest.param(operator.gt, marks=pytest.mark.xfail()),
pytest.param(operator.ge, marks=pytest.mark.xfail()),
pytest.param(operator.ne, marks=pytest.mark.xfail()),
],
)
def test_df_sr_binop(gsr, colnames, op):
data = [[0, 2, 5], [3, None, 5], [6, 7, np.nan]]
data = [[3.0, 2.0, 5.0], [3.0, None, 5.0], [6.0, 7.0, np.nan]]
data = dict(zip(colnames, data))

gsr = gsr.astype("float64")

gdf = cudf.DataFrame(data)
pdf = pd.DataFrame.from_dict(data)
pdf = gdf.to_pandas(nullable=True)

psr = gsr.to_pandas()
psr = gsr.to_pandas(nullable=True)

expect = op(pdf, psr)
got = op(gdf, gsr)
assert_eq(expect.astype(float), got.astype(float))
got = op(gdf, gsr).to_pandas(nullable=True)
assert_eq(expect, got, check_dtype=False)

expect = op(psr, pdf)
got = op(psr, pdf)
assert_eq(expect.astype(float), got.astype(float))
got = op(gsr, gdf).to_pandas(nullable=True)
assert_eq(expect, got, check_dtype=False)


@pytest.mark.parametrize(
Expand Down