pola-rs/polars · error

Altair has no method 'mark_{attr}'

Error message

Altair has no method 'mark_{attr}'

What it means

Raised by SeriesPlot.__getattr__ (py-polars/src/polars/series/plotting.py:177) when the requested chart type has no corresponding Altair mark_* method. s.plot.<attr> dispatches to alt.Chart.mark_<attr>; if Altair defines no such mark, polars raises AttributeError listing the missing 'mark_<attr>' name. Note that 'scatter' is special-cased to 'point' before the lookup.

Source

Thrown at py-polars/src/polars/series/plotting.py:177

        encodings: Encodings = {"x": "index", "y": self._series_name}
        return (
            alt.Chart(self._df.with_row_index())
            .mark_line(tooltip=True)
            .encode(**encodings, **kwargs)
            .interactive()
        )

    def __getattr__(self, attr: str) -> Callable[..., alt.Chart]:
        if self._series_name == "index":
            msg = f"Cannot call `plot.{attr}` when Series name is 'index'"
            raise ValueError(msg)
        if attr == "scatter":
            # alias `scatter` to `point` because of how common it is
            attr = "point"
        method = getattr(alt.Chart(self._df.with_row_index()), f"mark_{attr}", None)
        if method is None:
            msg = f"Altair has no method 'mark_{attr}'"
            raise AttributeError(msg)
        encodings: Encodings = {"x": "index", "y": self._series_name}

        accepts_tooltip_argument = "tooltip" in {
            value.name for value in inspect.signature(method).parameters.values()
        }
        if accepts_tooltip_argument:

            def func(**kwargs: EncodeKwds) -> alt.Chart:
                return method(tooltip=True).encode(**encodings, **kwargs).interactive()
        else:

            def func(**kwargs: EncodeKwds) -> alt.Chart:
                return method().encode(**encodings, **kwargs).interactive()

        return func

View on GitHub (pinned to df599052da)

Solutions

  1. Use a valid Altair mark name: plot.bar, plot.point (or plot.scatter alias), plot.line, plot.area, plot.tick, plot.rect, plot.boxplot
  2. For histograms use the dedicated method: s.plot.hist() instead of s.plot.histogram()
  3. Check Altair docs for the full mark_* list your installed version supports

Example fix

# before
s.plot.histogram()  # AttributeError: Altair has no method 'mark_histogram'

# after
s.plot.hist()
# generic marks:
s.plot.bar()
Defensive patterns

Strategy: validation

Validate before calling

import altair as alt

MARKS = {m.removeprefix("mark_") for m in dir(alt.Chart) if m.startswith("mark_")}

def plot_mark(s, mark: str, **kw):
    mark = {"scatter": "point"}.get(mark, mark)
    if mark not in MARKS:
        raise ValueError(f"unknown mark {mark!r}; choose from {sorted(MARKS)}")
    return getattr(s.plot, mark)(**kw)

Try / catch

try:
    chart = getattr(s.plot, mark)()
except AttributeError as e:
    if "Altair has no method" in str(e):
        raise ValueError(f"unsupported chart type {mark!r}; use hist/bar/point/line/area/tick/boxplot") from e
    raise

Prevention

When it happens

Trigger: s.plot.histogram() (Altair has no mark_histogram — use plot.hist), s.plot.boxplot() (the mark is mark_boxplot, so this actually works; but s.plot.box would not), s.plot.pie() (no mark_pie in Altair's standard API), or typos like s.plot.barr().

Common situations: Guessing chart-method names by analogy with other libraries (matplotlib/pandas: .hist(), .scatter(), .box()); typos; expecting every chart type to exist. The fix is to use the name Altair's mark_* methods define.

Related errors


AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16). Data as JSON: /api/errors/d1ae5ef2f3ae0088. Report an issue: GitHub.