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

Warn when downscaling decimal columns #8492

Merged
merged 4 commits into from
Jun 18, 2021
Merged
Changes from 2 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
11 changes: 11 additions & 0 deletions python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from decimal import Decimal
from typing import Any, Sequence, Tuple, Union, cast
from warnings import warn

import cupy as cp
import numpy as np
Expand Down Expand Up @@ -146,6 +147,16 @@ def _decimal_quantile(
def as_decimal_column(
self, dtype: Dtype, **kwargs
) -> "cudf.core.column.DecimalColumn":
if (
isinstance(dtype, Decimal64Dtype)
and isinstance(self.dtype, Decimal64Dtype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid this check, given. self is a DecimalColumn?

and dtype.scale < self.dtype.scale
):
warn(
"cuDF truncates when downcasting decimals to a lower scale. "
"To round, use Series.round() or DataFrame.round()."
)

if dtype == self.dtype:
return self
return libcudf.unary.cast(self, dtype)
Expand Down