{"record":{"id":"f59079f2854da89e","repo":"pola-rs/polars","slug":"altair-5-4-0-is-required-for-plot","errorCode":null,"errorMessage":"altair>=5.4.0 is required for `.plot`","messagePattern":"altair>=5\\.4\\.0 is required for `\\.plot`","errorType":"exception","errorClass":"ModuleUpgradeRequiredError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":501,"sourceCode":"\n        Examples\n        --------\n        Histogram:\n\n        >>> s = pl.Series([1, 4, 4, 6, 2, 4, 3, 5, 5, 7, 1])\n        >>> s.plot.hist()  # doctest: +SKIP\n\n        KDE plot:\n\n        >>> s.plot.kde()  # doctest: +SKIP\n\n        Line plot:\n\n        >>> s.plot.line()  # doctest: +SKIP\n        \"\"\"  # noqa: W505\n        if not _ALTAIR_AVAILABLE or parse_version(altair.__version__) < (5, 4, 0):\n            msg = \"altair>=5.4.0 is required for `.plot`\"\n            raise ModuleUpgradeRequiredError(msg)\n        return SeriesPlot(self)\n\n    @classmethod\n    def _from_pyseries(cls, pyseries: PySeries) -> Self:\n        series = cls.__new__(cls)\n        series._s = pyseries\n        return series\n\n    @classmethod\n    def _import_arrow_from_c(cls, name: str_, pointers: list_[tuple[int, int]]) -> Self:\n        \"\"\"\n        Construct a Series from Arrows C interface.\n\n        Parameters\n        ----------\n        name\n            The name that should be given to the `Series`.\n        pointers","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L483-L519","documentation":"Series.plot is a convenience API that wraps the Series in a SeriesPlot backed by the altair visualization library. Polars requires altair >= 5.4.0 for the `.plot` namespace, and raises ModuleUpgradeRequiredError when altair is either not installed or installed at an older version. The error exists so users get a clear, actionable message instead of an obscure AttributeError from a missing altair feature.","triggerScenarios":"Calling any method under Series.plot (e.g. s.plot.line(), s.plot.point(), s.plot.bar()) while altair is not installed, or installed at a version below 5.4.0 (the _ALTAIR_AVAILABLE flag or parse_version(altair.__version__) < (5, 4, 0) check in Series.plot fails).","commonSituations":"Fresh environments where polars was installed without the 'plot' extra (polars[plot]); pinned altair versions in requirements.txt/lockfiles from before the 5.4.0 release; projects that dropped altair during dependency cleanup but kept plotting code; CI images with stale cached altair wheels.","solutions":["Install or upgrade altair to at least 5.4.0: pip install -U 'altair>=5.4.0' (or pip install 'polars[plot]' which pulls in the required altair).","If using uv/poetry/conda, add altair>=5.4.0 to the project dependencies and re-lock (e.g. poetry add 'altair@>=5.4.0').","If you cannot upgrade altair, replace s.plot.line() with an explicit chart: alt.Chart(df).mark_line().encode(x=..., y=...) after converting the Series with s.to_frame()."],"exampleFix":"// before\nimport polars as pl\ns = pl.Series('y', [1, 2, 3])\ns.plot.line()  # ModuleUpgradeRequiredError: altair>=5.4.0 is required for `.plot`\n\n// after\n# pip install -U 'altair>=5.4.0'\nimport polars as pl\ns = pl.Series('y', [1, 2, 3])\ns.plot.line()  # works","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec('altair') is None or __import__('altair').__version__ < '5.4.0':\n    raise RuntimeError('Install altair>=5.4.0 (pip install -U \"altair>=5.4.0\") before using .plot')","typeGuard":"def can_plot() -> bool:\n    try:\n        import altair\n        return tuple(int(p) for p in altair.__version__.split('.')[:2]) >= (5, 4)\n    except ImportError:\n        return False","tryCatchPattern":null,"preventionTips":["Declare polars with the plot extra (polars[plot]) or add altair>=5.4.0 to project dependencies so environments are complete.","Pin altair>=5.4.0 in requirements/lockfiles and re-lock after adding plotting code.","Add an import-time capability check in modules that use .plot, failing fast with a clear setup message.","Keep CI environments built from the same lockfile as development to avoid missing optional deps."],"tags":["python","polars","altair","dependency-version","plotting"],"backgroundTag":"missing-dependency","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}