Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 19 additions & 2 deletions python/cudf_polars/cudf_polars/dsl/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,13 +919,30 @@ def _(
dtype: DataType,
schema: Schema,
) -> expr.Expr:
left = translator.translate_expr(n=node.left, schema=schema)
right = translator.translate_expr(n=node.right, schema=schema)
if plc.traits.is_boolean(dtype.plc_type) and node.op == pl_expr.Operator.TrueDivide:
dtype = DataType(pl.Float64())
if node.op == pl_expr.Operator.TrueDivide and (
plc.traits.is_fixed_point(left.dtype.plc_type)
or plc.traits.is_fixed_point(right.dtype.plc_type)
):
f64 = DataType(pl.Float64())
return expr.Cast(
dtype,
expr.BinOp(
f64,
expr.BinOp._MAPPING[node.op],
expr.Cast(f64, left),
expr.Cast(f64, right),
),
)

return expr.BinOp(
dtype,
expr.BinOp._MAPPING[node.op],
translator.translate_expr(n=node.left, schema=schema),
translator.translate_expr(n=node.right, schema=schema),
left,
right,
)


Expand Down
15 changes: 15 additions & 0 deletions python/cudf_polars/tests/expressions/test_numeric_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

from decimal import Decimal

import pytest

import polars as pl

from cudf_polars.testing.asserts import (
assert_gpu_result_equal,
)
from cudf_polars.utils.versions import POLARS_VERSION_LT_132

dtypes = [
pl.Int8,
Expand Down Expand Up @@ -106,3 +109,15 @@ def test_true_div_boolean_column(divisor):
q = df.select(pl.col("a") / divisor)

assert_gpu_result_equal(q)


def test_true_div_with_decimals():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Don't check output dtype for polars version < 1.32 because of #19975

df = pl.LazyFrame(
{
"foo": [Decimal("1.00"), Decimal("2.00"), Decimal("3.00"), None],
"bar": [Decimal("4.00"), Decimal("5.00"), Decimal("6.00"), Decimal("1.00")],
},
schema={"foo": pl.Decimal(15, 2), "bar": pl.Decimal(15, 2)},
)
q = df.select(pl.col("bar") / pl.col("foo"))
assert_gpu_result_equal(q, check_dtypes=not POLARS_VERSION_LT_132)
Loading