Skip to content

Commit

Permalink
Remove cudf._lib.round in favor of inlining pylibcudf (#17430)
Browse files Browse the repository at this point in the history
Contributes to #17317

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Matthew Murray (https://github.com/Matt711)

URL: #17430
  • Loading branch information
mroeschke authored Dec 6, 2024
1 parent 467cf7a commit 1a62b46
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 46 deletions.
1 change: 0 additions & 1 deletion python/cudf/cudf/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ set(cython_sources
orc.pyx
parquet.pyx
reduce.pyx
round.pyx
scalar.pyx
sort.pyx
stream_compaction.pyx
Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
orc,
parquet,
reduce,
round,
sort,
stream_compaction,
string_casting,
Expand Down
39 changes: 0 additions & 39 deletions python/cudf/cudf/_lib/round.pyx

This file was deleted.

19 changes: 14 additions & 5 deletions python/cudf/cudf/core/column/numerical_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1a62b46

Please sign in to comment.