Skip to content
/ cudf Public
forked from rapidsai/cudf

Commit

Permalink
Check for zero cudf.Scalar in __floordiv__ and __mod__
Browse files Browse the repository at this point in the history
  • Loading branch information
wence- committed Nov 8, 2022
1 parent b5dd7b1 commit e3f50dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/column/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
(tmp.dtype.type in int_float_dtype_mapping)
and (tmp.dtype.type != np.bool_)
and (
(np.isscalar(tmp) and (0 == tmp))
(
(np.isscalar(tmp) or isinstance(tmp, cudf.Scalar))
and (0 == tmp)
)
or (
(isinstance(tmp, NumericalColumn)) and (0.0 in tmp)
)
Expand Down
15 changes: 15 additions & 0 deletions python/cudf/cudf/tests/test_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,21 @@ def test_binop_bool_uint(func, rhs):
)


@pytest.mark.parametrize(
"series_dtype", (np.bool_, np.int8, np.uint8, np.int64, np.uint64)
)
@pytest.mark.parametrize(
"scalar_dtype", (np.bool_, np.int8, np.uint8, np.int64, np.uint64)
)
def test_floordiv_zero_float64(series_dtype, scalar_dtype):
sr = pd.Series([1, 2, 3], dtype=series_dtype)
cr = cudf.from_pandas(sr)

utils.assert_eq(
(sr // scalar_dtype(0)), (cr // cudf.Scalar(0, dtype=scalar_dtype))
)


def test_series_misc_binop():
pds = pd.Series([1, 2, 4], name="abc xyz")
gds = cudf.Series([1, 2, 4], name="abc xyz")
Expand Down

0 comments on commit e3f50dc

Please sign in to comment.