From bda0b054ddc625fc220ac1687af068387d9c8d3f Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Mon, 4 Jan 2021 14:57:17 -0800 Subject: [PATCH 1/3] normalize cudf.NA to scalar --- python/cudf/cudf/core/series.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/cudf/cudf/core/series.py b/python/cudf/cudf/core/series.py index 0ea76877bab..027da95bb91 100644 --- a/python/cudf/cudf/core/series.py +++ b/python/cudf/cudf/core/series.py @@ -1569,6 +1569,8 @@ def _normalize_binop_value(self, other): return other._column elif isinstance(other, Index): return Series(other)._column + elif other is cudf.NA: + return cudf.Scalar(other, dtype=self.dtype) else: return self._column.normalize_binop_value(other) From df57ca14378c021b73caddfc8a7f62fadde6bdda Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Mon, 4 Jan 2021 15:43:29 -0800 Subject: [PATCH 2/3] pass string scalars to cat --- python/cudf/cudf/core/column/string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cudf/cudf/core/column/string.py b/python/cudf/cudf/core/column/string.py index ea14f23ea44..f5df440b865 100644 --- a/python/cudf/cudf/core/column/string.py +++ b/python/cudf/cudf/core/column/string.py @@ -4966,7 +4966,7 @@ def binary_operator(self, op, rhs, reflect=False): lhs = self if reflect: lhs, rhs = rhs, lhs - if isinstance(rhs, (StringColumn, str)): + if isinstance(rhs, (StringColumn, str, cudf.Scalar)): if op == "add": return lhs.str().cat(others=rhs) elif op in ("eq", "ne", "gt", "lt", "ge", "le"): From 1550ba9cb7717384465282f6c9778317b6c8346a Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Thu, 14 Jan 2021 14:16:33 -0800 Subject: [PATCH 3/3] tests --- python/cudf/cudf/tests/test_binops.py | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/python/cudf/cudf/tests/test_binops.py b/python/cudf/cudf/tests/test_binops.py index be1cef50ec3..93bc6d1c573 100644 --- a/python/cudf/cudf/tests/test_binops.py +++ b/python/cudf/cudf/tests/test_binops.py @@ -19,6 +19,7 @@ DATETIME_TYPES, FLOAT_TYPES, INTEGER_TYPES, + NUMERIC_TYPES, TIMEDELTA_TYPES, ) @@ -1527,3 +1528,42 @@ def test_binops_with_lhs_numpy_scalar(frame, dtype): expected = pd.Index(expected) utils.assert_eq(expected, got) + + +@pytest.mark.parametrize( + "dtype", + [ + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "float32", + "float64", + "datetime64[ns]", + "datetime64[us]", + "datetime64[ms]", + "datetime64[s]", + "timedelta64[ns]", + "timedelta64[us]", + "timedelta64[ms]", + "timedelta64[s]", + ], +) +@pytest.mark.parametrize("op", _operators_comparison) +def test_binops_with_NA_consistent(dtype, op): + data = [1, 2, 3] + sr = cudf.Series(data, dtype=dtype) + + result = getattr(sr, op)(cudf.NA) + if dtype in NUMERIC_TYPES: + if op == "ne": + expect_all = True + else: + expect_all = False + assert (result == expect_all).all() + elif dtype in DATETIME_TYPES & TIMEDELTA_TYPES: + assert result._column.null_count == len(data)