diff --git a/python/cudf/cudf/_lib/CMakeLists.txt b/python/cudf/cudf/_lib/CMakeLists.txt index 4e1bf860872..cff25f5752c 100644 --- a/python/cudf/cudf/_lib/CMakeLists.txt +++ b/python/cudf/cudf/_lib/CMakeLists.txt @@ -21,7 +21,6 @@ set(cython_sources orc.pyx parquet.pyx reduce.pyx - round.pyx scalar.pyx sort.pyx stream_compaction.pyx diff --git a/python/cudf/cudf/_lib/__init__.py b/python/cudf/cudf/_lib/__init__.py index c79d5100622..05310d8d232 100644 --- a/python/cudf/cudf/_lib/__init__.py +++ b/python/cudf/cudf/_lib/__init__.py @@ -10,7 +10,6 @@ orc, parquet, reduce, - round, sort, stream_compaction, string_casting, diff --git a/python/cudf/cudf/_lib/round.pyx b/python/cudf/cudf/_lib/round.pyx deleted file mode 100644 index f961c09e6f6..00000000000 --- a/python/cudf/cudf/_lib/round.pyx +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2021-2024, NVIDIA CORPORATION. - -from cudf.core.buffer import acquire_spill_lock - -from cudf._lib.column cimport Column - -import pylibcudf as plc -from pylibcudf.round import RoundingMethod - - -@acquire_spill_lock() -def round(Column input_col, int decimal_places=0, how="half_even"): - """ - Round column values to the given number of decimal places - - Parameters - ---------- - input_col : Column whose values will be rounded - decimal_places : The number or decimal places to round to - - Returns - ------- - A Column with values rounded to the given number of decimal places - """ - if how not in {"half_even", "half_up"}: - raise ValueError("'how' must be either 'half_even' or 'half_up'") - - how = ( - RoundingMethod.HALF_EVEN if how == "half_even" - else RoundingMethod.HALF_UP - ) - - return Column.from_pylibcudf( - plc.round.round( - input_col.to_pylibcudf(mode="read"), - decimal_places, - how - ) - ) diff --git a/python/cudf/cudf/core/column/numerical_base.py b/python/cudf/cudf/core/column/numerical_base.py index ea242e34edb..3f9abdabc2f 100644 --- a/python/cudf/cudf/core/column/numerical_base.py +++ b/python/cudf/cudf/core/column/numerical_base.py @@ -3,7 +3,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, cast +from typing import TYPE_CHECKING, Literal, cast import numpy as np @@ -246,12 +246,21 @@ def corr(self, other: NumericalBaseColumn) -> float: return cov / lhs_std / rhs_std def round( - self, decimals: int = 0, how: str = "half_even" + self, + decimals: int = 0, + how: Literal["half_even", "half_up"] = "half_even", ) -> NumericalBaseColumn: if not cudf.api.types.is_integer(decimals): - raise TypeError("Values in decimals must be integers") - """Round the values in the Column to the given number of decimals.""" - return libcudf.round.round(self, decimal_places=decimals, how=how) + raise TypeError("Argument 'decimals' must an integer") + if how not in {"half_even", "half_up"}: + raise ValueError(f"{how=} must be either 'half_even' or 'half_up'") + plc_how = plc.round.RoundingMethod[how.upper()] + with acquire_spill_lock(): + return type(self).from_pylibcudf( # type: ignore[return-value] + plc.round.round( + self.to_pylibcudf(mode="read"), decimals, plc_how + ) + ) def _scan(self, op: str) -> ColumnBase: return libcudf.reduce.scan(