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

[REVIEW] Remove overflow error during decimal binops #12063

Merged
merged 2 commits into from
Nov 4, 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
10 changes: 9 additions & 1 deletion python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,12 @@ def _get_decimal_type(lhs_dtype, rhs_dtype, op):
# to try the next dtype
continue

raise OverflowError("Maximum supported decimal type is Decimal128")
# Instead of raising an overflow error, we create a `Decimal128Dtype`
# with max possible scale & precision, see example of this demonstration
# here: https://learn.microsoft.com/en-us/sql/t-sql/data-types/
# precision-scale-and-length-transact-sql?view=sql-server-ver16#examples
scale = min(
scale, cudf.Decimal128Dtype.MAX_PRECISION - (precision - scale)
)
precision = min(cudf.Decimal128Dtype.MAX_PRECISION, max_precision)
return cudf.Decimal128Dtype(precision=precision, scale=scale)
8 changes: 7 additions & 1 deletion python/cudf/cudf/tests/test_decimal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021, NVIDIA CORPORATION.
# Copyright (c) 2021-2022, NVIDIA CORPORATION.

import decimal
from decimal import Decimal
Expand Down Expand Up @@ -377,3 +377,9 @@ def test_decimal_invalid_precision():

with pytest.raises(pa.ArrowInvalid):
_ = cudf.Series([Decimal("300")], dtype=cudf.Decimal64Dtype(2, 1))


def test_decimal_overflow():
s = cudf.Series([Decimal("0.0009384233522166997927180531650178250")])
result = s * s
assert_eq(cudf.Decimal128Dtype(precision=38, scale=37), result.dtype)