Skip to content

An InvalidOperationError (Conversion from str failed) occurs when using the GPU engine #25604

@asddfl

Description

@asddfl

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

ctx = pl.SQLContext()

t1 = pl.LazyFrame(
    {
        "c0": ['1969-12-08 17:00:01'],
    }
)
ctx.register("t1", t1)

result = t1.with_columns(pl.col('c0').cast(pl.Int64, strict=False))
print("CPU Result:")
print(result.collect())

print("GPU Result:")
print(result.collect(engine=pl.GPUEngine(raise_on_fail=True)))

Log output

CPU Result:
shape: (1, 1)
┌──────┐
│ c0   │
│ ---  │
│ i64  │
╞══════╡
│ null │
└──────┘
GPU Result:
Traceback (most recent call last):
  File "/xxx/bug.py", line 19, in <module>
    print(result.collect(engine=pl.GPUEngine(raise_on_fail=True)))
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/polars/_utils/deprecation.py", line 97, in wrapper
    return function(*args, **kwargs)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/polars/lazyframe/opt_flags.py", line 328, in wrapper
    return function(*args, **kwargs)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/polars/lazyframe/frame.py", line 2415, in collect
    return wrap_df(ldf.collect(engine, callback))
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/polars/_utils/scan.py", line 27, in _execute_from_rust
    return function(with_columns, *args)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/callback.py", line 263, in _callback
    return evaluate_streaming(ir, config_options)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/experimental/parallel.py", line 287, in evaluate_streaming
    return get_scheduler(config_options)(graph, key).to_polars()
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/experimental/scheduler.py", line 149, in synchronous_scheduler
    cache[k] = _execute_task(graph[k], cache)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/experimental/scheduler.py", line 51, in _execute_task
    return arg[0](*(_execute_task(a, cache) for a in arg[1:]))
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/dsl/ir.py", line 2571, in do_evaluate
    columns = [c.evaluate(df) for c in exprs]
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/dsl/ir.py", line 2571, in <listcomp>
    columns = [c.evaluate(df) for c in exprs]
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/dsl/expressions/base.py", line 204, in evaluate
    return self.value.evaluate(df, context=context).rename(self.name)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/dsl/expressions/base.py", line 114, in evaluate
    return self.do_evaluate(df, context=context)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/dsl/expressions/unary.py", line 46, in do_evaluate
    return column.astype(self.dtype, stream=df.stream)
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/containers/column.py", line 302, in astype
    self._handle_string_cast(plc_dtype, stream=stream), dtype=dtype
  File "/xxx/anaconda3/envs/polars/lib/python3.10/site-packages/cudf_polars/containers/column.py", line 368, in _handle_string_cast
    raise InvalidOperationError("Conversion from `str` failed.")
polars.exceptions.InvalidOperationError: Conversion from `str` failed.

Issue description

A InvalidOperationError will occur when using cast(pl.Int64, strict=False) and the GPU engines.

Expected behavior

No error will occur when using the GPU engine.
The output is consistent when using the CPU and GPU engines.

Installed versions

--------Version info---------
Polars:              1.34.0
Index type:          UInt32
Platform:            Linux-6.14.0-35-generic-x86_64-with-glibc2.39
Python:              3.10.19 (main, Oct 21 2025, 16:43:05) [GCC 11.2.0]
Runtime:             rt32

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               2025.10.0
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           <not installed>
numpy                1.26.4
openpyxl             <not installed>
pandas               2.3.3
polars_cloud         <not installed>
pyarrow              <not installed>
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
cuda-bindings     12.9.4
cuda-pathfinder   1.3.2
cuda-python       12.9.4
cudf-polars       26.2.0a104
nvidia-ml-py      13.580.82
nvtx              0.2.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-gpuArea: gpu enginebugSomething isn't workingneeds triageAwaiting prioritization by a maintainerpythonRelated to Python Polars

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions