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

Enable rounding for Decimal32 and Decimal64 in cuDF #17332

Merged
merged 19 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
8 changes: 7 additions & 1 deletion python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3970,7 +3970,13 @@ def round(self, decimals=0, how="half_even"):

cols = (
col.round(decimals[name], how=how)
if name in decimals and col.dtype.kind in "fiu"
if name in decimals
and (
col.dtype.kind in "fiu"
or isinstance(
col.dtype, (cudf.Decimal32Dtype, cudf.Decimal64Dtype)
)
)
else col.copy(deep=True)
for name, col in self._column_labels_and_values
)
Expand Down
63 changes: 63 additions & 0 deletions python/cudf/cudf/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,69 @@ def test_round_nan_as_null_false(series, decimal):
assert_eq(result, expected, atol=1e-10)


@pytest.mark.parametrize(
"data, dtype, decimals, expected_half_up, expected_half_even",
[
(
[1.234, 2.345, 3.456],
cudf.Decimal32Dtype(precision=5, scale=3),
2,
[1.23, 2.35, 3.46],
[1.23, 2.34, 3.46],
),
(
[1.234, 2.345, 3.456],
cudf.Decimal32Dtype(precision=5, scale=3),
0,
[1.0, 2.0, 3.0],
[1.0, 2.0, 3.0],
),
(
[1.234, 2.345, 3.456],
cudf.Decimal32Dtype(precision=5, scale=3),
3,
[1.234, 2.345, 3.456],
[1.234, 2.345, 3.456],
),
(
[1.234567, 2.345678, 3.456789],
cudf.Decimal64Dtype(precision=10, scale=6),
4,
[1.2346, 2.3457, 3.4568],
[1.2346, 2.3457, 3.4568],
),
(
[1.234567, 2.345678, 3.456789],
cudf.Decimal64Dtype(precision=10, scale=6),
2,
[1.23, 2.35, 3.46],
[1.23, 2.35, 3.46],
),
(
[1.234567, 2.345678, 3.456789],
cudf.Decimal64Dtype(precision=10, scale=6),
6,
[1.234567, 2.345678, 3.456789],
[1.234567, 2.345678, 3.456789],
),
],
)
def test_series_round_decimal(
data, dtype, decimals, expected_half_up, expected_half_even
):
ser = cudf.Series(data).astype(dtype)

result_half_up = ser.round(decimals=decimals, how="half_up").astype(dtype)
a-hirota marked this conversation as resolved.
Show resolved Hide resolved
expected_ser_half_up = cudf.Series(expected_half_up).astype(dtype)
assert_eq(result_half_up, expected_ser_half_up)

result_half_even = ser.round(decimals=decimals, how="half_even").astype(
dtype
)
expected_ser_half_even = cudf.Series(expected_half_even).astype(dtype)
assert_eq(result_half_even, expected_ser_half_even)


@pytest.mark.parametrize("ps", _series_na_data())
@pytest.mark.parametrize("nan_as_null", [True, False, None])
def test_series_isnull_isna(ps, nan_as_null):
Expand Down
Loading