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

[gpuCI] Forward-merge branch-22.10 to branch-22.12 [skip gpuci] #11820

Merged
merged 1 commit into from
Sep 29, 2022
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
9 changes: 8 additions & 1 deletion python/cudf/cudf/core/scalar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.

import decimal
import operator
from collections import OrderedDict

import numpy as np
Expand Down Expand Up @@ -353,7 +354,13 @@ def _binaryop(self, other, op: str):
def _dispatch_scalar_binop(self, other, op):
if isinstance(other, Scalar):
other = other.value
return getattr(self.value, op)(other)
try:
func = getattr(operator, op)
except AttributeError:
func = getattr(self.value, op)
else:
return func(self.value, other)
return func(other)

def _unaop_result_type_or_error(self, op):
if op == "__neg__" and self.dtype == "bool":
Expand Down
7 changes: 7 additions & 0 deletions python/cudf/cudf/tests/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,10 @@ def test_default_float_bitwidth_scalar(default_float_bitwidth):
# Test that float scalars are default to 32 bits under user options.
slr = cudf.Scalar(128.0)
assert slr.dtype == np.dtype(f"f{default_float_bitwidth//8}")


def test_scalar_numpy_casting():
# binop should upcast to wider type
s1 = cudf.Scalar(1, dtype=np.int32)
s2 = np.int64(2)
assert s1 < s2