pola-rs/polars · error · ShapeError

Series length mismatch: expected {n!r}, found {m!r}

Error message

Series length mismatch: expected {n!r}, found {m!r}

What it means

dot() length check: the dot product requires both Series to have the same number of elements; the guard raises ShapeError with expected vs found lengths when they differ. Triggered by mismatched vectors or arrays of different length.

Source

Thrown at py-polars/src/polars/series/series.py:5724

        Examples
        --------
        >>> s = pl.Series("a", [1, 2, 3])
        >>> s2 = pl.Series("b", [4.0, 5.0, 6.0])
        >>> s.dot(s2)
        32.0

        Parameters
        ----------
        other
            Series (or array) to compute dot product with.
        """
        if not isinstance(other, Series):
            other = Series(other)
        if len(self) != len(other):
            n, m = len(self), len(other)
            msg = f"Series length mismatch: expected {n!r}, found {m!r}"
            raise ShapeError(msg)
        return self._s.dot(other._s)

    def mode(self, *, maintain_order: bool = False) -> Series:
        """
        Compute the most occurring value(s).

        Can return multiple Values.

        Parameters
        ----------
        maintain_order
            Maintain order of data. This requires more work.

        Examples
        --------
        >>> s = pl.Series("a", [1, 2, 2, 3])
        >>> s.mode()
        shape: (1,)

View on GitHub (pinned to 68506541d2)

Solutions

  1. Make the lengths match: pass values with the same length as the expected Series length, or adjust the expected length.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at py-polars/src/polars/series/series.py:5880 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/bc97c6b1e7eeb4d4. Report an issue: GitHub.