{"record":{"id":"31813e95cad02b62","repo":"pola-rs/polars","slug":"sink-batches-is-not-supported-by-type-self-n","errorCode":null,"errorMessage":"`sink_batches` is not supported by {type(self).__name__}","messagePattern":"`sink_batches` is not supported by (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/engine.py","lineNumber":292,"sourceCode":"        mkdir: bool,\n        optimizations: QueryOptFlags,\n    ) -> None:\n        \"\"\"See :meth:`polars.LazyFrame.sink_ndjson`.\"\"\"\n        msg = f\"`sink_ndjson` is not supported by {type(self).__name__}\"\n        raise NotImplementedError(msg)\n\n    def sink_batches(\n        self,\n        lf: LazyFrame,\n        function: Callable[[DataFrame], bool | None],\n        *,\n        chunk_size: int | None,\n        maintain_order: bool,\n        optimizations: QueryOptFlags,\n    ) -> None:\n        \"\"\"See :meth:`polars.LazyFrame.sink_batches`.\"\"\"\n        msg = f\"`sink_batches` is not supported by {type(self).__name__}\"\n        raise NotImplementedError(msg)\n\n\nclass _LocalEngine(Engine):\n    \"\"\"Base for in-process engines backed by `PyLazyFrame`.\"\"\"\n\n    _name: ClassVar[str]\n\n    # Subclasses that do not call `super().__init__()` still see the default value.\n    monitoring: bool | None = None\n    \"\"\"Whether queries are monitored (``None`` uses the configured default).\"\"\"\n\n    def __init__(self, *, monitoring: bool | None = None) -> None:\n        if monitoring:\n            from polars._utils.monitoring import activate_monitoring\n\n            activate_monitoring()\n        self.monitoring = monitoring\n","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/lazyframe/engine.py#L274-L310","documentation":"`sink_batches` streams a LazyFrame's output to a user callback in batches, letting the caller control flushing/termination. Only engines with streaming sink support implement it; the base `Engine` raises NotImplementedError with this message otherwise.","triggerScenarios":"Calling `LazyFrame.sink_batches(lf, function, engine=<engine>)` where the engine does not override `sink_batches` (e.g. a custom engine).","commonSituations":"Custom batched write handlers (e.g. chunked uploads) used with a non-streaming or user-defined engine; porting streaming code between engines.","solutions":["Use `engine='streaming'`, which implements `sink_batches`.","Use `collect_batches` (on a supporting engine) and invoke your callback per batch manually.","Implement `sink_batches` in your custom Engine subclass.","Check the engine's method support matrix in polars docs."],"exampleFix":"// before\nlf.sink_batches(lambda df: None, engine=\"custom\")\n// after\nlf.sink_batches(lambda df: None, engine=\"streaming\")","handlingStrategy":"try-catch","validationCode":"if type(engine_obj).sink_batches is Engine.sink_batches:\n    engine = \"streaming\"","typeGuard":"def supports_batch_sink(engine: object) -> bool:\n    return type(engine).sink_batches is not Engine.sink_batches","tryCatchPattern":"try:\n    lf.sink_batches(fn, engine=eng)\nexcept NotImplementedError:\n    for batch in lf.collect_batches():\n        fn(batch)","preventionTips":["Use engine='streaming' for sink_batches","Implement sink_batches in custom engines","Provide a collect_batches-based fallback for callback-style writes"],"tags":["python","polars","streaming","callback","not-implemented"],"backgroundTag":"method-not-implemented","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"}