ImportError: cannot import name 'Appender' from 'statsmodels.compat.pandas'
Third-person routing text. Fixes ImportError for Appender from statsmodels.compat.pandas: statsmodels removed the shim. Import Appender from pandas.util._decorators instead, or upgrade the dependent package. Use when an agent hits this on code written against old statsmodels. Not for other statsmodels.compat names.
TL;DR: statsmodels removed its Appender shim. Import it from pandas.util._decorators instead, or upgrade the package that does the old import.
The error
ImportError: cannot import name 'Appender' from 'statsmodels.compat.pandas'Fix it
- Replace the import in your code:
from pandas.util._decorators import AppenderExpected: no import error; Appender behaves the same.
- If the bad import is inside a third-party package, upgrade that package:
pip install -U [the-package]Expected: new release uses the new path.
- Verify the import that failed now works.
When this applies
Use this when code does from statsmodels.compat.pandas import Appender on a recent statsmodels.
When it does not apply
If the error names a different statsmodels.compat member, check whether the shim still exists. If statsmodels itself will not import, reinstall it.
Compatibility
Recent statsmodels versions where the compat shim was removed. pandas.util._decorators.Appender exists across pandas 1.x and 2.x.
Root cause
statsmodels.compat.pandas held shims for pandas API drift, including a re-export of pandas' Appender docstring decorator. statsmodels cleaned the module up and dropped the re-export; anything importing it breaks.
Edge cases
Appender is itself semi-private in pandas (pandas.util._decorators), so prefer upgrading the dependent package over relying on the new path long-term. Grep for other statsmodels.compat imports when upgrading.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.