pola-rs/polars · error · AttributeError

Altair has no method 'mark_

Error message

Altair has no method 'mark_{attr}'

What it means

SeriesPlot.__getattr__ resolves the attribute to an Altair mark_{attr} method. If Altair's Chart has no such mark method, it raises AttributeError('Altair has no method mark_{attr}'). This guards against typos and unsupported mark names for the installed Altair version.

Solutions

  1. Check dir(alt.Chart) for available mark_* methods
  2. Use a valid Altair mark: bar, point, line, area, circle, tick, rule, rect, arc
  3. Remember scatter is aliased: s.plot.scatter() maps to mark_point
  4. Upgrade Altair if the mark you need exists only in newer versions

Example fix

// before
s.plot.barchart()
// after
s.plot.bar()  # Altair mark_bar
Defensive patterns

Strategy: validation

Validate before calling

import altair as alt
if not hasattr(alt.Chart, f"mark_{attr}"):
    raise ValueError(f"unknown mark: {attr}")
getattr(s.plot, attr)()

Type guard

def is_valid_mark(attr: str) -> bool:
    import altair as alt
    return hasattr(alt.Chart, f"mark_{attr}")

Try / catch

try:
    chart = s.plot.barchart()
except AttributeError as e:
    if "Altair has no method" in str(e):
        chart = s.plot.bar()  # fall back to a valid mark

Prevention

When it happens

Trigger: Calling s.plot.barchart(), s.plot.barh(), s.plot.lines(), or any misspelled/unsupported mark name like s.plot.sactter() where f'mark_{attr}' doesn't exist on alt.Chart.

Common situations: Expecting pandas-bokeh/matplotlib-style plot method names; Altair version differences where newer marks (e.g. mark_arc in older versions) don't exist; typos like s.plot.pointt().

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: 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 fe841f959e)