{"record":{"id":"0be3eba2a8005a09","repo":"pola-rs/polars","slug":"the-remote-engine-can-only-sink-to-a-uri-or-a-par","errorCode":null,"errorMessage":"the remote engine can only sink to a URI or a `PartitionBy`, got {qualified_type_name(path)!r}","messagePattern":"the remote engine can only sink to a URI or a `PartitionBy`, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/engine_remote.py","lineNumber":226,"sourceCode":"        # Polars Cloud streams the result back through `scan_arrow_c_stream`, so this\n        # really is a `_CollectBatches`; its stubs just type it as a plain iterator.\n        return self._target(lf).collect_batches(  # type: ignore[return-value]\n            maintain_order=maintain_order, optimizations=optimizations\n        )\n\n    # -- Sinks --------------------------------------------------------------------\n\n    @staticmethod\n    def _sink_uri(path: Any) -> str | PartitionBy:\n        \"\"\"Validate a Polars Cloud sink target.\"\"\"\n        from polars.io.partition import PartitionBy\n\n        if not isinstance(path, (str, PartitionBy)):\n            msg = (\n                \"the remote engine can only sink to a URI or a `PartitionBy`, got \"\n                f\"{qualified_type_name(path)!r}\"\n            )\n            raise TypeError(msg)\n        return path\n\n    @staticmethod\n    def _reject_if_set(**kwargs: Any) -> None:\n        \"\"\"Reject options unsupported by Polars Cloud.\"\"\"\n        for name, value in kwargs.items():\n            if value:\n                msg = f\"`{name}` is not supported by the remote engine\"\n                raise ValueError(msg)\n\n    def sink_parquet(\n        self,\n        lf: LazyFrame,\n        path: str | Path | IO[bytes] | PartitionBy,\n        *,\n        compression: ParquetCompression,\n        compression_level: int | None,\n        statistics: bool | str | dict[str, bool],","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/lazyframe/engine_remote.py#L208-L244","documentation":"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.","triggerScenarios":"lf.sink_parquet(pathlib.Path('out.parquet'), engine=RemoteEngine(...)) or passing IO[bytes]/BytesIO while the selected engine resolves to remote.","commonSituations":"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.","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."],"exampleFix":"// before\nlf.sink_parquet(Path('out.parquet'), engine=remote_engine)\n\n// after\nlf.sink_parquet('s3://bucket/out.parquet', engine=remote_engine)","handlingStrategy":"type-guard","validationCode":"if isinstance(path, (Path, io.IOBase)):\n    raise TypeError('remote engine sinks need a URI string or PartitionBy')","typeGuard":"def is_remote_sink_target(path: object) -> bool:\n    from polars._utils.partition import PartitionBy\n    return isinstance(path, (str, PartitionBy))","tryCatchPattern":"try:\n    lf.sink_parquet(path, engine=remote_engine)\nexcept TypeError as e:\n    if 'can only sink to a URI' in str(e):\n        lf.sink_parquet(str(path), engine=remote_engine)\n    else:\n        raise","preventionTips":["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."],"tags":["polars","polars-cloud","type-mismatch","sink"],"backgroundTag":"type-mismatch","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}