{"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":"exception","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/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/io/csv/_utils.py#L10-L39","documentation":"The strict branch of _check_arg_is_1byte (py-polars/src/polars/io/csv/_utils.py:27-34), used for separator and eol_char (can_be_empty=False), requires the value to be exactly one UTF-8 byte: neither the empty string nor multi-byte or multi-character values are accepted. The CSV parser delimits on single bytes, so multi-char delimiters like '\\r\\n' or '::' are not representable.","triggerScenarios":"pl.read_csv(f, eol_char='\\r\\n') (2 bytes - classic CRLF attempt); separator='::'; separator='\\u2016' (double vertical line, 3 bytes); separator='' (empty not allowed here, unlike quote_char).","commonSituations":"Windows line-ending files where users pass eol_char='\\r\\n'; logical multi-character delimiters from log formats; localized Unicode separators.","solutions":["Use the single-byte equivalent: eol_char='\\n' (polars handles CRLF files with the default), separator='|' not '\\uff5c'","For multi-char delimited files, pre-split lines in Python or transform the file before read_csv","For genuinely non-ASCII single characters, transcode the file or replace the delimiter during preprocessing"],"exampleFix":"# before\ndf = pl.read_csv(\"f.csv\", eol_char=\"\\r\\n\")\n# after\ndf = pl.read_csv(\"f.csv\", eol_char=\"\\n\")","handlingStrategy":"validation","validationCode":"def check_strict_one_byte(arg_name: str, value: str) -> None:\n    n = len(value.encode(\"utf-8\"))\n    if n != 1:\n        raise ValueError(\n            f\"{arg_name}={value!r} must be exactly 1 byte; \"\n            \"multi-char delimiters need preprocessing\"\n        )","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.read_csv(path, eol_char=eol)\nexcept ValueError as e:\n    if \"single byte\" in str(e) and eol == \"\\r\\n\":\n        df = pl.read_csv(path, eol_char=\"\\n\")\n    else:\n        raise","preventionTips":["Do not pass '\\r\\n' as eol_char; the default '\\n' handles CRLF files","Preprocess multi-character delimiters ('::', '||') before read_csv","Validate separator/eol_char byte length in config validation"],"tags":["polars","csv","encoding","delimiter","valueerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}