{"record":{"id":"0ee9ebc50c12e7e8","repo":"pola-rs/polars","slug":"format-must-be-one-of-binary-json-got-f","errorCode":null,"errorMessage":"`format` must be one of {'binary', 'json'}, got {format!r}","messagePattern":"`format` must be one of (.+?), got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/meta.py","lineNumber":449,"sourceCode":"\n        >>> expr = pl.col(\"foo\").sum().over(\"bar\")\n        >>> bytes = expr.meta.serialize()\n        >>> type(bytes)\n        <class 'bytes'>\n\n        The bytes can later be deserialized back into an `Expr` object.\n\n        >>> import io\n        >>> pl.Expr.deserialize(io.BytesIO(bytes))\n        <Expr ['col(\"foo\").sum().over([col(\"ba…'] at ...>\n        \"\"\"\n        if format == \"binary\":\n            serializer = self._pyexpr.serialize_binary\n        elif format == \"json\":\n            serializer = self._pyexpr.serialize_json\n        else:\n            msg = f\"`format` must be one of {{'binary', 'json'}}, got {format!r}\"\n            raise ValueError(msg)\n\n        return serialize_polars_object(serializer, file, format)\n\n    @overload\n    def tree_format(\n        self,\n        *,\n        return_as_string: Literal[False] = ...,\n        schema: None | SchemaDict = None,\n    ) -> None: ...\n\n    @overload\n    def tree_format(\n        self, *, return_as_string: Literal[True], schema: None | SchemaDict = None\n    ) -> str: ...\n\n    def tree_format(\n        self, *, return_as_string: bool = False, schema: None | SchemaDict = None","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/meta.py#L431-L467","documentation":"Expr.meta.serialize() only accepts format='binary' or format='json'. Any other value falls into the else branch and raises this ValueError. Serialization backends are enumerated, so unknown formats are rejected before touching the file/stream.","triggerScenarios":"Calling Expr.meta.serialize(file, format='yaml') (or 'txt', 'pickle', '', None, case variants like 'JSON').","commonSituations":"Assuming YAML/other formats are supported; passing a format variable read from config with wrong casing; typos like 'bin' or 'js'.","solutions":["Use format='binary' (default) or format='json'.","Fix casing: pass 'json' not 'JSON'.","Validate the format against a literal set before calling serialize."],"exampleFix":"// before\nexpr.meta.serialize(f, format='yaml')\n// after\nexpr.meta.serialize(f, format='json')","handlingStrategy":"validation","validationCode":"VALID_FORMATS = {'binary', 'json'}\nif format not in VALID_FORMATS:\n    raise ValueError(f'format must be one of {VALID_FORMATS}, got {format!r}')","typeGuard":"from typing import Literal\ndef is_valid_format(f: str) -> bool:\n    return f in ('binary', 'json')","tryCatchPattern":"try:\n    expr.meta.serialize(file, format=fmt)\nexcept ValueError:\n    expr.meta.serialize(file, format='binary')","preventionTips":["Use Literal['binary', 'json'] annotations for format parameters.","Lowercase config-sourced format strings before use.","Check the docs: serialize supports exactly two formats."],"tags":["python","polars","value-error","serialization"],"backgroundTag":"invalid-enum-value","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"}