{"record":{"id":"37c1097a8e0e1a7e","repo":"pola-rs/polars","slug":"arg-name-arg-should-be-a-single-byte-charact-37c109","errorCode":null,"errorMessage":"{arg_name}=\"{arg}\" should be a single byte character, but is {arg_byte_length} bytes long","messagePattern":"(.+?)=\"(.+?)\" should be a single byte character, but is (.+?) bytes long","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/csv/_utils.py","lineNumber":28,"sourceCode":"\ndef _check_arg_is_1byte(\n    arg_name: str, arg: str | None, *, can_be_empty: bool = False\n) -> None:\n    if isinstance(arg, str):\n        arg_byte_length = len(arg.encode(\"utf-8\"))\n        if can_be_empty:\n            if arg_byte_length > 1:\n                msg = (\n                    f'{arg_name}=\"{arg}\" should be a single byte character or empty,'\n                    f\" but is {arg_byte_length} bytes long\"\n                )\n                raise ValueError(msg)\n        elif arg_byte_length != 1:\n            msg = (\n                f'{arg_name}=\"{arg}\" should be a single byte character, but is'\n                f\" {arg_byte_length} bytes long\"\n            )\n            raise ValueError(msg)\n\n\ndef _update_columns(df: DataFrame, new_columns: Sequence[str]) -> DataFrame:\n    if df.width > len(new_columns):\n        cols = df.columns\n        for i, name in enumerate(new_columns):\n            cols[i] = name\n        new_columns = cols\n    df.columns = list(new_columns)\n    return df\n","sourceCodeStart":10,"sourceCodeEnd":39,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/csv/_utils.py#L10-L39","documentation":"CSV single-character arguments passed to `read_csv`, `scan_csv`, `write_csv`, or `sink_csv` must encode to exactly one UTF-8 byte. `_check_arg_is_1byte` raises this ValueError when the argument's byte length is not exactly 1 (the non-empty branch). This exists because the Rust CSV reader/writer treats these options as single-byte tokens.","triggerScenarios":"Passing a separator, quote_char, or similar option that is empty or longer than one byte where an empty string is not allowed — e.g. `separator=\"\"`, `separator=\"; \"`, or a multi-byte character like `separator=\"§\"` in some encodings.","commonSituations":"Passing an empty string thinking it means 'default'; using strings like \"\\r\\n\" or \"::\" as separators; Unicode characters whose UTF-8 encoding exceeds one byte; locale/keyboard introducing smart quotes as quote_char.","solutions":["Check `len(arg.encode(\"utf-8\")) == 1` before the call and fix the value.","Use a single ASCII character, e.g. `separator=\";\"`, `quote_char='\"'`.","For multi-character delimiters, pre-process the file or read it as a plain text and split manually — polars CSV options only accept one byte.","If you meant the default comma, omit `separator` entirely."],"exampleFix":"// before\npl.read_csv(\"data.csv\", quote_char=\"”\")  # multi-byte smart quote\n# after\npl.read_csv(\"data.csv\", quote_char='\"')","handlingStrategy":"validation","validationCode":"assert len(sep.encode(\"utf-8\")) == 1, f\"separator must be 1 byte: {sep!r}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass \"\" for arguments that don't allow empty (separator, etc.).","Beware non-ASCII characters: check `len(s.encode('utf-8'))`, not `len(s)`.","For multi-char delimiters, preprocess the file rather than forcing a CSV option."],"tags":["python","csv","validation","arguments"],"backgroundTag":"invalid-argument-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"}