statsmodels: ImportError of module from 'statsmodels.compat.pandas'

Describe the bug

Failed to import due to compatibility issue with pandas

I am currently using the statsmodels version from the master branch @ git+https://github.com/statsmodels/statsmodels

For Pandas: any version starting from 0.21 to 1.0.0 produces this error Please help!

Code Sample, a copy-pastable example if possible

ImportError                               Traceback (most recent call last)
<ipython-input-220-23b3b387c9ee> in <module>
----> 1 import statsmodels.api as sm
      2 
      3 X = sm.add_constant(final_df_attributes_coded)
      4 estimator = sm.OLS(final_df_label_fact, X)
      5 estimator.fit()

~/anaconda3/lib/python3.7/site-packages/statsmodels/api.py in <module>
     18 from . import robust
     19 from .robust.robust_linear_model import RLM
---> 20 from .discrete.discrete_model import (Poisson, Logit, Probit,
     21                                       MNLogit, NegativeBinomial,
     22                                       GeneralizedPoisson,

~/anaconda3/lib/python3.7/site-packages/statsmodels/discrete/discrete_model.py in <module>
     26 from scipy.stats import nbinom
     27 
---> 28 from statsmodels.compat.pandas import Appender
     29 
     30 import statsmodels.tools.tools as tools

ImportError: cannot import name 'Appender' from 'statsmodels.compat.pandas' (/Users/tophunghuy/anaconda3/lib/python3.7/site-packages/statsmodels/compat/pandas.py)

Note: As you can see, there are many issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates.

Note: Please be sure you are using the latest released version of statsmodels, or a recent build of master. If your problem has been fixed in an unreleased version, you might be able to use master until a new release occurs.

Note: If you are using a released version, have you verified that the bug exists in the master branch of this repository? It helps the limited resources if we know problems exist in the current master so that they do not need to check whether the code sample produces a bug in the next release.

If the issue has not been resolved, please file it in the issue tracker.

Expected Output

Expected to sucessfully import statsmodels

Output of import statsmodels.api as sm;

Failed to import due to compatibility issue with pandas

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

Haven’t tried every single release of pandas yet. A bit cumbersome

What happens if you look in statsmodels/compat/pandas.py? Do you see Appender? I suspect your statsmodel install is broken. You could also try pip uninstall statsmodels && pip install statsmodels --pgrade

@NiveshTayal @jingyuzheng make sure to check that your editor/environment is using those updated versions - i.e. in your .ipynb check if pd.version shows 1.0.3 and if it doesn’t restart your environment. But with your versions of pandas and statsmodels, it should work

I have sm 0.11.0 and pandas 1.0.3 which work together.