pola-rs/polars · error · ModuleNotFoundError
great_tables is required for `.style`
Error message
great_tables is required for `.style`
What it means
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.
Source
Thrown at py-polars/src/polars/dataframe/frame.py:820
>>> df.style.tab_style(
... style.fill("yellow"),
... loc.body(rows=pl.col("measure_a") == pl.col("measure_a").max()),
... ) # doctest: +SKIP
Put a spanner (high-level label) over measure columns:
>>> df.style.tab_spanner(
... "Measures", cs.starts_with("measure")
... ) # doctest: +SKIP
Format measure_b values to two decimal places:
>>> df.style.fmt_number("measure_b", decimals=2) # doctest: +SKIP
"""
if not _GREAT_TABLES_AVAILABLE:
msg = "great_tables is required for `.style`"
raise ModuleNotFoundError(msg)
return great_tables.GT(self)
@property
def shape(self) -> tuple[int, int]:
"""
Get the shape of the DataFrame.
Examples
--------
>>> df = pl.DataFrame({"foo": [1, 2, 3, 4, 5]})
>>> df.shape
(5, 1)
"""
return self._df.shape()
@property
def height(self) -> int:View on GitHub (pinned to df599052da)
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
Example fix
# before
df.style.fmt_number('x', decimals=2) # ModuleNotFoundError
# after
# pip install great_tables
df.style.fmt_number('x', decimals=2) Defensive patterns
Strategy: validation
Validate before calling
import importlib.util
GREAT_TABLES = importlib.util.find_spec('great_tables') is not None
styled = df.style if GREAT_TABLES else df # skip styling when unavailable Try / catch
try:
out = df.style.fmt_number('x', decimals=2)
except ModuleNotFoundError as e:
if 'great_tables' in str(e):
out = df # or render df.to_html() as a plain fallback
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- could not get Databricks token: databricks-sdk is not instal
- altair>=5.4.0 is required for `.plot`
- invalid dtype_format value: {fmt!r} (expected format string,
- Required package 'torch' not installed.\nPlease install it u
- altair>=5.4.0 is required for `.plot`
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/d33714228a3654f4.
Report an issue: GitHub.