Skip to content

Commit

Permalink
Enable not equal for decimal columns (#8143)
Browse files Browse the repository at this point in the history
This enables the not equal operation for binary operations involving decimal columns.

Authors:
  - https://github.com/ChrisJar

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #8143
  • Loading branch information
ChrisJar authored May 4, 2021
1 parent 770dc38 commit 53e1c66
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def binary_operator(self, op, other, reflect=False):
result.dtype.precision = _binop_precision(
self.dtype, other.dtype, op
)
elif op in ("eq", "lt", "gt", "le", "ge"):
elif op in ("eq", "ne", "lt", "gt", "le", "ge"):
if not isinstance(
other,
(DecimalColumn, cudf.core.column.NumericalColumn, cudf.Scalar),
Expand Down
75 changes: 75 additions & 0 deletions python/cudf/cudf/tests/test_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,33 @@ def _decimal_series(input, dtype):
[True, None],
bool,
),
(
operator.ne,
["0.06", "0.42"],
cudf.Decimal64Dtype(scale=2, precision=3),
["0.18", "0.42"],
cudf.Decimal64Dtype(scale=2, precision=3),
[True, False],
bool,
),
(
operator.ne,
["1.33", "1.21"],
cudf.Decimal64Dtype(scale=2, precision=3),
["0.1899", "1.21"],
cudf.Decimal64Dtype(scale=4, precision=5),
[True, False],
bool,
),
(
operator.ne,
["300", None],
cudf.Decimal64Dtype(scale=-2, precision=3),
["110", "5500"],
cudf.Decimal64Dtype(scale=-1, precision=4),
[True, None],
bool,
),
(
operator.lt,
["0.18", "0.42", "1.00"],
Expand Down Expand Up @@ -2066,6 +2093,30 @@ def test_binops_decimal(args):
cudf.Series([True, False, None], dtype=bool),
cudf.Series([True, False, None], dtype=bool),
),
(
operator.ne,
["100", "42", "24", None],
cudf.Decimal64Dtype(scale=0, precision=3),
[100, 40, 24, 12],
cudf.Series([False, True, False, None], dtype=bool),
cudf.Series([False, True, False, None], dtype=bool),
),
(
operator.ne,
["10.1", "88", "11", None],
cudf.Decimal64Dtype(scale=1, precision=3),
[10, 42, 11, 12],
cudf.Series([True, True, False, None], dtype=bool),
cudf.Series([True, True, False, None], dtype=bool),
),
(
operator.ne,
["100.000", "42", "23.999", None],
cudf.Decimal64Dtype(scale=3, precision=6),
[100, 42, 24, 12],
cudf.Series([False, False, True, None], dtype=bool),
cudf.Series([False, False, True, None], dtype=bool),
),
(
operator.lt,
["100", "40", "28", None],
Expand Down Expand Up @@ -2459,6 +2510,30 @@ def decimal_series(input, dtype):
cudf.Series([True, False, None], dtype=bool),
cudf.Series([True, False, None], dtype=bool),
),
(
operator.ne,
["100.00", "41", None],
cudf.Decimal64Dtype(scale=2, precision=5),
100,
cudf.Series([False, True, None], dtype=bool),
cudf.Series([False, True, None], dtype=bool),
),
(
operator.ne,
["100.123", "120.21", None],
cudf.Decimal64Dtype(scale=3, precision=6),
decimal.Decimal("100.123"),
cudf.Series([False, True, None], dtype=bool),
cudf.Series([False, True, None], dtype=bool),
),
(
operator.ne,
["100.123", "41", "120.21", None],
cudf.Decimal64Dtype(scale=3, precision=6),
cudf.Scalar(decimal.Decimal("100.123")),
cudf.Series([False, True, True, None], dtype=bool),
cudf.Series([False, True, True, None], dtype=bool),
),
(
operator.gt,
["100.00", "41", "120.21", None],
Expand Down

0 comments on commit 53e1c66

Please sign in to comment.