{"record":{"id":"d33714228a3654f4","repo":"pola-rs/polars","slug":"great-tables-is-required-for-style","errorCode":null,"errorMessage":"great_tables is required for `.style`","messagePattern":"great_tables is required for `\\.style`","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/dataframe/frame.py","lineNumber":820,"sourceCode":"\n        >>> df.style.tab_style(\n        ...     style.fill(\"yellow\"),\n        ...     loc.body(rows=pl.col(\"measure_a\") == pl.col(\"measure_a\").max()),\n        ... )  # doctest: +SKIP\n\n        Put a spanner (high-level label) over measure columns:\n\n        >>> df.style.tab_spanner(\n        ...     \"Measures\", cs.starts_with(\"measure\")\n        ... )  # doctest: +SKIP\n\n        Format measure_b values to two decimal places:\n\n        >>> df.style.fmt_number(\"measure_b\", decimals=2)  # doctest: +SKIP\n        \"\"\"\n        if not _GREAT_TABLES_AVAILABLE:\n            msg = \"great_tables is required for `.style`\"\n            raise ModuleNotFoundError(msg)\n\n        return great_tables.GT(self)\n\n    @property\n    def shape(self) -> tuple[int, int]:\n        \"\"\"\n        Get the shape of the DataFrame.\n\n        Examples\n        --------\n        >>> df = pl.DataFrame({\"foo\": [1, 2, 3, 4, 5]})\n        >>> df.shape\n        (5, 1)\n        \"\"\"\n        return self._df.shape()\n\n    @property\n    def height(self) -> int:","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/dataframe/frame.py#L802-L838","documentation":"The df.style accessor returns great_tables.GT(self) for spreadsheet-style formatting, and great_tables is an optional dependency. If the import failed (_GREAT_TABLES_AVAILABLE false), accessing the property raises ModuleNotFoundError with a message naming the missing package, since there is no fallback formatter.","triggerScenarios":"Any access of df.style (property access itself raises) in an environment without great_tables installed; partially installed/broken great_tables package; environments provisioned without the 'format' extra.","commonSituations":"Notebook servers or slim Docker images where only core polars is installed; shared code that styles reports and is run in CI without viz dependencies.","solutions":["pip install great_tables","Add it to the project's dependencies/environment lockfile so style-using code runs everywhere","Guard with importlib.util.find_spec('great_tables') before styling, and degrade to plain repr/to_html when absent"],"exampleFix":"# before\ndf.style.fmt_number('x', decimals=2)  # ModuleNotFoundError\n\n# after\n# pip install great_tables\ndf.style.fmt_number('x', decimals=2)","handlingStrategy":"validation","validationCode":"import importlib.util\n\nGREAT_TABLES = importlib.util.find_spec('great_tables') is not None\nstyled = df.style if GREAT_TABLES else df  # skip styling when unavailable","typeGuard":null,"tryCatchPattern":"try:\n    out = df.style.fmt_number('x', decimals=2)\nexcept ModuleNotFoundError as e:\n    if 'great_tables' in str(e):\n        out = df  # or render df.to_html() as a plain fallback\n    else:\n        raise","preventionTips":["Add great_tables to project dependencies where styling code runs (including CI and Docker images)","Feature-detect with importlib.util.find_spec before styling","Keep styling logic in a separate optional module imported only when the package exists"],"tags":["optional-dependency","great-tables","style","formatting"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}