diff --git a/python/cudf/cudf/core/scalar.py b/python/cudf/cudf/core/scalar.py index 263469f07f2..1e998ae37e2 100644 --- a/python/cudf/cudf/core/scalar.py +++ b/python/cudf/cudf/core/scalar.py @@ -56,7 +56,14 @@ def __init__(self, value, dtype=None): self._host_value = None self._host_dtype = None self._device_value = None - if isinstance(value, DeviceScalar): + + if isinstance(value, Scalar): + if value._is_host_value_current: + self._host_value = value._host_value + self._host_dtype = value._host_dtype + else: + self._device_value = value._device_value + elif isinstance(value, DeviceScalar): self._device_value = value else: self._host_value, self._host_dtype = self._preprocess_host_value( diff --git a/python/cudf/cudf/tests/test_scalar.py b/python/cudf/cudf/tests/test_scalar.py index 003e46c7e0d..1a8aca2b2a3 100644 --- a/python/cudf/cudf/tests/test_scalar.py +++ b/python/cudf/cudf/tests/test_scalar.py @@ -289,3 +289,14 @@ def test_device_scalar_direct_construction(value): assert s.dtype == "object" else: assert s.dtype == dtype + + +@pytest.mark.parametrize("value", SCALAR_VALUES) +def test_construct_from_scalar(value): + value = cudf.utils.utils.to_cudf_compatible_scalar(value) + x = cudf.Scalar(1, value.dtype) + y = cudf.Scalar(x) + assert x.value == y.value + + # check that this works: + y.device_value