{"record":{"id":"ce4b0ca0878b7480","repo":"pola-rs/polars","slug":"specified-column-names-do-not-start-with-column","errorCode":null,"errorMessage":"specified column names do not start with 'column_', but autogenerated header names were requested","messagePattern":"specified column names do not start with 'column_', but autogenerated header names were requested","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/csv/functions.py","lineNumber":317,"sourceCode":"    if sample_size != 1024:\n        msg = \"the `sample_size` parameter was deprecated in 1.10.0, it doesn't do anything anymore\"\n        issue_deprecation_warning(msg)\n\n    _check_arg_is_1byte(\"separator\", separator, can_be_empty=False)\n    _check_arg_is_1byte(\"quote_char\", quote_char, can_be_empty=True)\n    _check_arg_is_1byte(\"eol_char\", eol_char, can_be_empty=False)\n\n    projection, columns = parse_columns_arg(columns)\n    storage_options = storage_options or {}\n\n    if columns and not has_header:\n        for column in columns:\n            if not column.startswith(\"column_\"):\n                msg = (\n                    \"specified column names do not start with 'column_',\"\n                    \" but autogenerated header names were requested\"\n                )\n                raise ValueError(msg)\n\n    if schema_overrides is not None and not isinstance(\n        schema_overrides, (dict, Sequence)\n    ):\n        msg = \"`schema_overrides` should be of type list or dict\"\n        raise TypeError(msg)\n\n    if (\n        use_pyarrow\n        and schema_overrides is None\n        and n_rows is None\n        and n_threads is None\n        and not low_memory\n        and null_values is None\n    ):\n        include_columns: Sequence[str] | None = None\n        if columns:\n            if not has_header:","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/io/csv/functions.py#L299-L335","documentation":"In read_csv (py-polars/src/polars/io/csv/functions.py:311-318), when string `columns` is supplied together with has_header=False, the only valid names are the autogenerated 'column_0', 'column_1', ... ones, because no header exists to resolve arbitrary names against. If any requested name does not start with 'column_', the match would silently fail, so polars raises ValueError up front.","triggerScenarios":"pl.read_csv('f.csv', has_header=False, columns=['a','b']); headerless sensor/log exports where friendly names are requested directly instead of via renaming or projection.","commonSituations":"Headerless data dumps from instruments/logs where users still want final names immediately; combining has_header=False with name-based selection copied from a headed-file workflow.","solutions":["Select by position instead: columns=[0,1] works with has_header=False, then rename the result","Read with autogenerated names and rename: df.rename({'column_0': 'a', ...}) or use new_columns","If the file actually has a header row, remove has_header=False"],"exampleFix":"# before\ndf = pl.read_csv(\"f.csv\", has_header=False, columns=[\"a\", \"b\"])\n# after\ndf = pl.read_csv(\"f.csv\", has_header=False, columns=[0, 1]).rename({\"column_0\": \"a\", \"column_1\": \"b\"})","handlingStrategy":"validation","validationCode":"def columns_for_headerless(columns) -> list:\n    if isinstance(columns, list) and any(\n        isinstance(c, str) and not c.startswith(\"column_\") for c in columns\n    ):\n        raise ValueError(\n            \"with has_header=False, select by index and rename after reading\"\n        )\n    return columns","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.read_csv(path, has_header=False, columns=cols)\nexcept ValueError as e:\n    if \"autogenerated header\" in str(e):\n        df = pl.read_csv(path, has_header=False).rename(dict(zip(df.columns, cols)))\n    else:\n        raise","preventionTips":["For headerless files, default to index-based projection + rename","Keep the column_0 naming convention in mind when selecting by name without a header","Centralize the has_header/columns decision instead of mixing conventions"],"tags":["polars","csv","header","columns","valueerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}