Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
hooks:
- id: mypy
additional_dependencies: [
"polars>=1.30,<1.39",
"polars>=1.35,<1.39",
"numpy",
pyarrow-stubs,
"pyarrow<24.0.0", # https://github.com/rapidsai/cudf/issues/22229
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/all_cuda-129_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies:
- packaging
- pandas>=2.0,<2.4.0
- pandoc
- polars>=1.30,<1.39
- polars>=1.35,<1.39
- pre-commit
- pyarrow>=19.0.0,<24
- pydata-sphinx-theme>=0.15.4
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/all_cuda-129_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies:
- packaging
- pandas>=2.0,<2.4.0
- pandoc
- polars>=1.30,<1.39
- polars>=1.35,<1.39
- pre-commit
- pyarrow>=19.0.0,<24
- pydata-sphinx-theme>=0.15.4
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/all_cuda-131_arch-aarch64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies:
- packaging
- pandas>=2.0,<2.4.0
- pandoc
- polars>=1.30,<1.39
- polars>=1.35,<1.39
- pre-commit
- pyarrow>=19.0.0,<24
- pydata-sphinx-theme>=0.15.4
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/all_cuda-131_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies:
- packaging
- pandas>=2.0,<2.4.0
- pandoc
- polars>=1.30,<1.39
- polars>=1.35,<1.39
- pre-commit
- pyarrow>=19.0.0,<24
- pydata-sphinx-theme>=0.15.4
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/cudf-polars/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ requirements:
- python
- pylibcudf =${{ version }}
- rapidsmpf =${{ minor_version }}
- polars>=1.30,<1.39
- polars>=1.35,<1.39
- packaging
- ${{ pin_compatible("cuda-version", upper_bound="x", lower_bound="x") }}
- if: cuda_major == "12"
Expand Down
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ dependencies:
# 'nvidia-ml-py' provides the 'pynvml' module
- &nvidia_ml_py nvidia-ml-py>=12
- packaging
- polars>=1.30,<1.39
- polars>=1.35,<1.39
- typing_extensions>=4.0.0
run_cudf_polars_experimental:
common:
Expand Down
6 changes: 1 addition & 5 deletions python/cudf_polars/cudf_polars/containers/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ def _dtype_to_header(dtype: pl.DataType) -> DataTypeHeader:
if name in SCALAR_NAME_TO_POLARS_TYPE_MAP:
return {"kind": "scalar", "name": name}
if isinstance(dtype, pl.Decimal):
# TODO: Add version guard once we support polars 1.34
# Also keep in mind the typing change in polars:
# https://github.com/pola-rs/polars/pull/25227
precision = dtype.precision if dtype.precision is not None else 38
return {
"kind": "decimal",
"precision": precision,
"precision": dtype.precision,
"scale": dtype.scale,
Comment thread
mroeschke marked this conversation as resolved.
Resolved
}
if isinstance(dtype, pl.Datetime):
Expand Down
82 changes: 18 additions & 64 deletions python/cudf_polars/cudf_polars/dsl/expressions/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from enum import IntEnum, auto
from typing import TYPE_CHECKING, Any, ClassVar, cast

from polars import Struct as pl_Struct, polars # type: ignore[attr-defined]
from polars import Struct as pl_Struct
from polars.exceptions import InvalidOperationError

import pylibcudf as plc
Expand All @@ -23,14 +23,15 @@
from cudf_polars.dsl.utils.reshape import broadcast
from cudf_polars.utils.dtypes import make_empty_column
from cudf_polars.utils.versions import (
POLARS_VERSION_LT_132,
POLARS_VERSION_LT_136,
POLARS_VERSION_LT_138,
)

if TYPE_CHECKING:
from typing import Self

from polars import polars # type: ignore[attr-defined]

from cudf_polars.containers import DataFrame, DataType

__all__ = ["StringFunction"]
Expand Down Expand Up @@ -292,21 +293,6 @@ def _validate_input(self) -> None:
raise NotImplementedError(
"strip operations only support scalar patterns"
)
elif self.name is StringFunction.Name.ZFill:
if isinstance(self.children[1], Literal):
_, width = self.children
assert isinstance(width, Literal)
if (
POLARS_VERSION_LT_132
and width.value is not None
and width.value < 0
): # pragma: no cover
dtypestr = polars.dtype_str_repr(width.dtype.polars_type)
raise InvalidOperationError(
f"conversion from `{dtypestr}` to `u64` "
f"failed in column 'literal' for 1 out of "
f"1 values: [{width.value}]"
) from None

@staticmethod
def _create_regex_program(
Expand Down Expand Up @@ -437,24 +423,6 @@ def do_evaluate(
else:
col_width = self.children[1].evaluate(df, context=context)
assert isinstance(col_width, Column)
all_gt_0 = plc.binaryop.binary_operation(
col_width.obj,
plc.Scalar.from_py(
0, plc.DataType(plc.TypeId.INT64), stream=df.stream
),
plc.binaryop.BinaryOperator.GREATER_EQUAL,
plc.DataType(plc.TypeId.BOOL8),
stream=df.stream,
)

if POLARS_VERSION_LT_132 and not plc.reduce.reduce(
all_gt_0,
plc.aggregation.all(),
plc.DataType(plc.TypeId.BOOL8),
stream=df.stream,
).to_py(stream=df.stream): # pragma: no cover
raise InvalidOperationError("fill conversion failed.")

return Column(
plc.strings.padding.zfill_by_widths(
column.obj, col_width.obj, stream=df.stream
Expand Down Expand Up @@ -981,21 +949,14 @@ def do_evaluate(
dtype=self.dtype,
)
elif self.name is StringFunction.Name.PadStart:
if POLARS_VERSION_LT_132: # pragma: no cover
(column,) = columns
width_arg, char = self.options
pad_width = cast(int, width_arg)
else:
(column, width_col) = columns
(char,) = self.options
# TODO: Maybe accept a string scalar in
# cudf::strings::pad to avoid DtoH transfer
# See https://github.com/rapidsai/cudf/issues/20202
width_py = width_col.obj.to_scalar(stream=df.stream).to_py(
stream=df.stream
)
assert width_py is not None
pad_width = int(width_py)
(column, width_col) = columns
(char,) = self.options
# TODO: Maybe accept a string scalar in
# cudf::strings::pad to avoid DtoH transfer
# See https://github.com/rapidsai/cudf/issues/20202
width_py = width_col.obj.to_scalar(stream=df.stream).to_py(stream=df.stream)
assert width_py is not None
pad_width = int(width_py)

return Column(
plc.strings.padding.pad(
Expand All @@ -1008,20 +969,13 @@ def do_evaluate(
dtype=self.dtype,
)
elif self.name is StringFunction.Name.PadEnd:
if POLARS_VERSION_LT_132: # pragma: no cover
(column,) = columns
width_arg, char = self.options
pad_width = cast(int, width_arg)
else:
(column, width_col) = columns
(char,) = self.options
# TODO: Maybe accept a string scalar in
# cudf::strings::pad to avoid DtoH transfer
width_py = width_col.obj.to_scalar(stream=df.stream).to_py(
stream=df.stream
)
assert width_py is not None
pad_width = int(width_py)
(column, width_col) = columns
(char,) = self.options
# TODO: Maybe accept a string scalar in
# cudf::strings::pad to avoid DtoH transfer
width_py = width_col.obj.to_scalar(stream=df.stream).to_py(stream=df.stream)
assert width_py is not None
pad_width = int(width_py)

return Column(
plc.strings.padding.pad(
Expand Down
50 changes: 10 additions & 40 deletions python/cudf_polars/cudf_polars/dsl/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
join_cuda_streams,
)
from cudf_polars.utils.versions import (
POLARS_VERSION_LT_131,
POLARS_VERSION_LT_134,
POLARS_VERSION_LT_136,
POLARS_VERSION_LT_137,
POLARS_VERSION_LT_138,
Expand Down Expand Up @@ -505,16 +503,7 @@ def __init__(
raise NotImplementedError(
"Read from cloud storage"
) # pragma: no cover; no test yet
if (
any(str(p).startswith("https:/") for p in self.paths)
and POLARS_VERSION_LT_131
): # pragma: no cover; polars passed us the wrong URI
# https://github.com/pola-rs/polars/issues/22766
raise NotImplementedError("Read from https")
if any(
str(p).startswith("file:/" if POLARS_VERSION_LT_131 else "file://")
for p in self.paths
):
if any(str(p).startswith("file://") for p in self.paths):
raise NotImplementedError("Read from file URI")
if self.typ == "csv":
if any(
Expand Down Expand Up @@ -1980,19 +1969,15 @@ def _strip_predicate_casts(node: expr.Expr) -> expr.Expr:
):
return child

if (
not POLARS_VERSION_LT_134
and isinstance(child, expr.ColRef)
and (
(
plc.traits.is_floating_point(src.plc_type)
and plc.traits.is_floating_point(dst.plc_type)
)
or (
plc.traits.is_integral(src.plc_type)
and plc.traits.is_integral(dst.plc_type)
and src.plc_type.id() == dst.plc_type.id()
)
if isinstance(child, expr.ColRef) and (
(
plc.traits.is_floating_point(src.plc_type)
and plc.traits.is_floating_point(dst.plc_type)
)
or (
plc.traits.is_integral(src.plc_type)
and plc.traits.is_integral(dst.plc_type)
and src.plc_type.id() == dst.plc_type.id()
Comment thread
mroeschke marked this conversation as resolved.
Resolved
)
):
return child
Expand Down Expand Up @@ -3040,16 +3025,6 @@ def __init__(self, schema: Schema, name: str, options: Any, df: IR):
# same sub-shapes
raise NotImplementedError("Explode with more than one column")
self.options = (tuple(to_explode),)
elif POLARS_VERSION_LT_131 and self.name == "rename": # pragma: no cover
# As of 1.31, polars validates renaming in the IR
old, new, strict = self.options
if len(new) != len(set(new)) or (
set(new) & (set(df.schema.keys()) - set(old))
):
raise NotImplementedError(
"Duplicate new names in rename."
) # pragma: no cover
self.options = (tuple(old), tuple(new), strict)
elif self.name == "unpivot":
indices, pivotees, variable_name, value_name = self.options
value_name = "value" if value_name is None else value_name
Expand Down Expand Up @@ -3123,11 +3098,6 @@ def do_evaluate(
# No-op in our data model
# Don't think this appears in a plan tree from python
return df # pragma: no cover
elif POLARS_VERSION_LT_131 and name == "rename": # pragma: no cover
# final tag is "swapping" which is useful for the
# optimiser (it blocks some pushdown operations)
old, new, _ = options
return df.rename_columns(dict(zip(old, new, strict=True)))
elif name == "explode":
((to_explode,),) = options
index = df.column_names.index(to_explode)
Expand Down
Loading
Loading