pola-rs/polars · error
module {__name__!r} has no attribute {name!r}
Error message
module {__name__!r} has no attribute {name!r} What it means
Raised by the module-level __getattr__ (PEP 562) of the polars package: the accessed name is not a real attribute of the top-level `polars` namespace, and it is also not one of the deprecated re-exports (exceptions accessible at top-level, or dtype groups from polars.datatypes.group) which would have returned a deprecation warning instead. Polars only resolves known deprecated aliases here; everything else raises a plain AttributeError naming the module and the missing attribute.
Source
Thrown at py-polars/src/polars/__init__.py:560
)
return getattr(exceptions, name)
# Deprecate data type groups at top-level
import polars.datatypes.group as dtgroup
if name in dir(dtgroup):
from polars._utils.deprecation import issue_deprecation_warning
issue_deprecation_warning(
message=(
f"`{name}` was deprecated in version 1.0.0. Define your own data type groups or "
"use the `polars.selectors` module for selecting columns of a certain data type."
),
)
return getattr(dtgroup, name)
msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)
View on GitHub (pinned to df599052da)
Solutions
- Fix the typo — confirm the exact public name with `hasattr(pl, 'read_csv')` or the API reference
- If it was a top-level exception (e.g. `pl.NotFoundError`), import it from `polars.exceptions` instead
- If it was a dtype group (INTEGER, FLOAT, TEMPORAL, ...), replace with `polars.selectors` (e.g. `cs.integer()`) or define your own group of dtypes
- If the API disappeared entirely, check the polars changelog / 1.0 upgrade guide for the new location
Example fix
// before
import polars as pl
df = pl.read_cvs("data.csv") # AttributeError: module 'polars' has no attribute 'read_cvs'
// after
import polars as pl
df = pl.read_csv("data.csv")
// before (deprecated group path)
pl.NUMERIC_TYPES # warns, but works
// after
import polars.selectors as cs
df.select(cs.numeric()) Defensive patterns
Strategy: validation
Validate before calling
import polars as pl
name = "read_csv" # attribute you plan to use
if not hasattr(pl, name):
raise RuntimeError(f"polars {pl.__version__} has no attribute {name!r} — check spelling/API version")
fn = getattr(pl, name) Type guard
from typing import Any
import polars as pl
def has_polars_attr(name: str) -> bool:
"""True if the top-level polars namespace exposes `name` (PEP 562 aware)."""
return hasattr(pl, name) Try / catch
try:
fn = getattr(pl, name)
except AttributeError as e:
# name may be a deprecated alias that still resolves via __getattr__ with a warning,
# so only treat genuine absence as failure
raise MyAppConfigError(f"unsupported polars API: {name}") from e Prevention
- Pin the polars version and write code against that version's API docs
- Resolve API handles once at startup (module constants) so typos fail fast in one place
- For exception classes import from polars.exceptions; for dtype groups use polars.selectors instead of top-level names
- Run a quick `hasattr(pl, '...')` guard when calling dynamically-named APIs
When it happens
Trigger: Accessing any misspelled or nonexistent name on `pl`, e.g. `pl.read_cvs(...)`, `pl.data_frame(...)`, `pl.ArrowTypes`; or calling an API that was removed/moved rather than deprecated (top-level exception access moved to polars.exceptions in 1.0, dtype groups like INTEGER/TEMPORAL deprecated in 1.0).
Common situations: Typos picked up from autocomplete; code written for polars 0.x run under 1.x where names moved into submodules (`polars.exceptions`, `polars.selectors`, `polars.datatypes.group`); using a DataFrame/Series method as if it were a module-level function (`pl.shape`, `pl.columns`).
Related errors
- cannot select columns using key of type {qualified_type_name
- expected {df.width} values when selecting columns by boolean
- index {key} is out of bounds for DataFrame of height {num_ro
- cannot select rows using key of type {qualified_type_name(ke
- cannot treat Series of type {s.dtype} as indices
AI-assisted analysis of pola-rs/polars@df599052da (2026-08-16).
Data as JSON: /api/errors/29a8c8a7eeb95648.
Report an issue: GitHub.