pola-rs/polars · error · TypeError

`names` is not a sequence

Error message

`names` is not a sequence

What it means

Type-guard in PolarsDataFrame.select_columns_by_name: the interchange protocol requires column names as a Sequence[str]; passing a bare string (which is itself a Sequence of chars, hence the explicit check), an int, or an iterator triggers this TypeError. Pass a list of name strings.

Solutions

  1. Pass names as a sequence of strings (e.g. a list) rather than a single string or non-sequence value.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at py-polars/src/polars/interchange/dataframe.py:158 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19). Data as JSON: /api/errors/66f6e3ab345c124c. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/interchange/dataframe.py:158

            indices = list(indices)

        return PolarsDataFrame(
            self._df[:, indices],
            allow_copy=self._allow_copy,
        )

    def select_columns_by_name(self, names: Sequence[str]) -> PolarsDataFrame:
        """
        Create a new dataframe by selecting a subset of columns by name.

        Parameters
        ----------
        names
            Column names.
        """
        if not isinstance(names, Sequence):
            msg = "`names` is not a sequence"
            raise TypeError(msg)

        return PolarsDataFrame(
            self._df.select(names),
            allow_copy=self._allow_copy,
        )

    def get_chunks(self, n_chunks: int | None = None) -> Iterator[PolarsDataFrame]:
        """
        Return an iterator yielding the chunks of the dataframe.

        Parameters
        ----------
        n_chunks
            The number of chunks to return. Must be a multiple of the number of chunks
            in the dataframe. If set to `None` (default), returns all chunks.

        Notes
        -----

View on GitHub (pinned to 9b5d73fd00)