Skip to content

Commit

Permalink
Avoid nan_as_null op if nan_count is 0 (#10082)
Browse files Browse the repository at this point in the history
This PR avoid make `nan_as_null` a no-op if `nan_count` is 0, i.e., there are no nulls present.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - https://github.com/brandon-b-miller

URL: #10082
  • Loading branch information
galipremsagar authored Jan 25, 2022
1 parent 52a61b7 commit 127537e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,11 +1213,7 @@ def corr(self, other: ColumnBase):
)

def nans_to_nulls(self: T) -> T:
# Only floats can contain nan.
if self.dtype.kind != "f":
return self
newmask = libcudf.transform.nans_to_nulls(self)
return self.set_mask(newmask)
return self

def _process_for_reduction(
self, skipna: bool = None, min_count: int = 0
Expand Down
7 changes: 7 additions & 0 deletions python/cudf/cudf/core/column/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ def binary_operator(
lhs, rhs = (self, rhs) if not reflect else (rhs, self)
return libcudf.binaryop.binaryop(lhs, rhs, binop, out_dtype)

def nans_to_nulls(self: NumericalColumn) -> NumericalColumn:
# Only floats can contain nan.
if self.dtype.kind != "f" or self.nan_count == 0:
return self
newmask = libcudf.transform.nans_to_nulls(self)
return self.set_mask(newmask)

def normalize_binop_value(
self, other: ScalarLike
) -> Union[ColumnBase, ScalarLike]:
Expand Down

0 comments on commit 127537e

Please sign in to comment.