-
Notifications
You must be signed in to change notification settings - Fork 915
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
[BUG] Decimal downcast truncates, never rounds #8475
Comments
It's unclear to me whether rounding or truncation is the "true" desired behavior. It might be nice to make it configurable via argument to the cast call. |
TYPED_TEST(FixedPointTests, FixedPointCast)
{
using fp_wrapper = cudf::test::fixed_point_column_wrapper<int64_t>;
auto const input = fp_wrapper{{2311999, 2311213}, numeric::scale_type{-5}};
auto const expected = fp_wrapper{{2311, 2311}, numeric::scale_type{-2}};
auto const result = cudf::cast(input, make_fixed_point_data_type<numeric::decimal64>(-2));
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view());
} The behaviour that is expected from above can be attained from the TYPED_TEST(FixedPointTests, FixedPointRound)
{
using fp_wrapper = cudf::test::fixed_point_column_wrapper<int64_t>;
auto const input = fp_wrapper{{2311999, 2311213}, numeric::scale_type{-5}};
auto const expected = fp_wrapper{{2312, 2311}, numeric::scale_type{-2}};
auto const result = cudf::round(input, 2);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view());
} Note that truncation is consistent with what CNL does: https://godbolt.org/z/v8qWEYenY |
On the Python side, this could be exposed via the existing >>> df.a
a
0 23.11999999999
>>> df.a.round(2) # errors today, but should return:
a
0 23.12 |
Correction: after #8278, |
Given the rounding behavior is available in cudf/python/cudf/cudf/core/column/decimal.py Lines 150 to 157 in 90fe10b
|
When a decimal type in one precision is downcast to another precision, data is truncated instead of rounded.
Below is code that reproduces the behavior.
I expect the data to be rounded based on the next significant digit (e.g.)
Bare-metal, conda; nightly.
The text was updated successfully, but these errors were encountered: