pola-rs/polars · error · TypeError
the remote engine can only sink to a URI or a…
Error message
the remote engine can only sink to a URI or a `PartitionBy`, got {qualified_type_name(path)!r} What it means
When an engine is the remote engine, sink targets must be a URI string or a PartitionBy specification; arbitrary path objects (Path, file handles) are not supported by Polars Cloud and raise TypeError via _sink_uri.
Solutions
- Pass the destination as a URI string (e.g. 's3://bucket/out.parquet').
- Use PartitionBy for partitioned remote writes.
- If you need Path/file-handle sinks, use the in-memory or streaming engine instead.
Example fix
// before
lf.sink_parquet(Path('out.parquet'), engine=remote_engine)
// after
lf.sink_parquet('s3://bucket/out.parquet', engine=remote_engine) Defensive patterns
Strategy: type-guard
Validate before calling
if isinstance(path, (Path, io.IOBase)):
raise TypeError('remote engine sinks need a URI string or PartitionBy') Type guard
def is_remote_sink_target(path: object) -> bool:
from polars._utils.partition import PartitionBy
return isinstance(path, (str, PartitionBy)) Try / catch
try:
lf.sink_parquet(path, engine=remote_engine)
except TypeError as e:
if 'can only sink to a URI' in str(e):
lf.sink_parquet(str(path), engine=remote_engine)
else:
raise Prevention
- Always use URI strings for cloud/remote sinks; reserve Path objects for local engines.
- Note the remote engine rejects file-like objects (IO[bytes]) even though the type hint allows them locally.
When it happens
Trigger: lf.sink_parquet(pathlib.Path('out.parquet'), engine=RemoteEngine(...)) or passing IO[bytes]/BytesIO while the selected engine resolves to remote.
Common situations: Code that works with the local engine (Path objects, in-memory buffers) reused unchanged with the remote engine; writing to cloud storage requires a URI anyway.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- `arctan2` expected a `str` or `Expr` got a
- `arctan2` expected a `str` or `Expr` got a
- can only convert date/datetime to NaiveDateTime
- can only convert date/datetime to NaiveTime
- can't convert to Decimal
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/0be3eba2a8005a09.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/lazyframe/engine_remote.py:226
# Polars Cloud streams the result back through `scan_arrow_c_stream`, so this
# really is a `_CollectBatches`; its stubs just type it as a plain iterator.
return self._target(lf).collect_batches( # type: ignore[return-value]
maintain_order=maintain_order, optimizations=optimizations
)
# -- Sinks --------------------------------------------------------------------
@staticmethod
def _sink_uri(path: Any) -> str | PartitionBy:
"""Validate a Polars Cloud sink target."""
from polars.io.partition import PartitionBy
if not isinstance(path, (str, PartitionBy)):
msg = (
"the remote engine can only sink to a URI or a `PartitionBy`, got "
f"{qualified_type_name(path)!r}"
)
raise TypeError(msg)
return path
@staticmethod
def _reject_if_set(**kwargs: Any) -> None:
"""Reject options unsupported by Polars Cloud."""
for name, value in kwargs.items():
if value:
msg = f"`{name}` is not supported by the remote engine"
raise ValueError(msg)
def sink_parquet(
self,
lf: LazyFrame,
path: str | Path | IO[bytes] | PartitionBy,
*,
compression: ParquetCompression,
compression_level: int | None,
statistics: bool | str | dict[str, bool],View on GitHub (pinned to fe841f959e)