pola-rs/polars · error · ValueError

more new column names are specified than there are selected…

Error message

more new column names are specified than there are selected columns

What it means

Validation in read_csv: new_columns (renaming list) is longer than the set of columns actually selected via `columns`. There would be more new names than columns to apply them to. Make the two lists the same length.

Solutions

  1. Provide no more new column names than the number of selected columns.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at py-polars/src/polars/io/csv/functions.py:456 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-19). Data as JSON: /api/errors/abe14e015e0ad8e2. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/csv/functions.py:456

                        column_types=None,
                        include_columns=include_columns,
                        include_missing_columns=ignore_errors,
                    ),
                )
            except pa.ArrowInvalid as err:
                if raise_if_empty or "Empty CSV" not in str(err):
                    raise
                return pl.DataFrame()

        if not has_header:
            # Rename 'f0', 'f1', ... columns names autogenerated by pyarrow
            # to 'column_0', 'column_1', ...
            tbl = tbl.rename_columns(
                [f"column_{int(column[1:])}" for column in tbl.column_names]
            )
        elif not column_names and projection:
            # User selected columns by positional index (e.g. `columns=[0, 2]`).
            # pyarrow's include_columns only accepts names, so the read above
            # fetched every column; pick out the requested positions now.
            tbl = tbl.select(list(projection))

        df = pl.DataFrame._from_arrow(tbl)

        if new_columns:
            return _update_columns(df, new_columns)

        if row_index is not None:
            name, offset = row_index
            df = df.with_row_index(name, offset)

        return df

    def _scan(source: Any, encoding: CsvEncoding | str) -> pl.LazyFrame:
        return scan_csv(
            source,
            has_header=has_header,

View on GitHub (pinned to 68506541d2)