statsmodels / statsmodels

Statsmodels: statistical modeling and econometrics in Python
http://www.statsmodels.org/devel/
BSD 3-Clause "New" or "Revised" License
10.08k stars 2.88k forks source link

AttributeError: 'pandas._libs.properties.CachedProperty' object has no attribute 'func' #8565

Closed matteogabba closed 1 year ago

matteogabba commented 1 year ago

When I run the following function

ar_select_order(seg, ic='aic', maxlag=maxlag)

I got this error message:

AttributeError: 'pandas._libs.properties.CachedProperty' object has no attribute 'func'

I never had this error before.

I run statsmodels version 0.13.5, pandas 1.4.4, scipy 1.9.3, on python 3.10.8 - Windows 11.

It seems to be related to this issue: https://github.com/pandas-dev/pandas/issues/46474

Example code to reproduce the issue:

import numpy as np
from statsmodels.tsa.ar_model import ar_select_order

x = np.array([ 239.83424321,  167.82769927,   89.8979825 ,   17.62647364,
        -74.61471784, -191.46196454, -317.49363405, -433.59813467,
       -489.33239431, -455.19897332, -353.48805058, -204.69413008,
        -32.88659459,  117.75119101,  256.05341303,  397.52653686,
        515.63154499,  582.87703054,  583.32171956,  487.0195182 ,
        314.68294874,  125.31024905,  -30.53799281, -116.31588371,
       -126.40961168,  -89.9293596 ,  -48.88184062,  -30.33868059,
        -50.98321497,  -97.06902425, -142.25422065, -160.52544434,
       -126.66740122,  -13.4300123 ,  160.02713276,  327.34313901,
        445.05741572,  442.63448766,  383.42265294,  696.5343972 ,
       1476.03014088, 2780.59407187,           np.nan,           np.nan,
                 np.nan,           np.nan,           np.nan,           np.nan,
                 np.nan,           np.nan])

idx_seg = [ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34, 35, 36, 37, 38, 39, 40, 41]

maxlag = 5

select = ar_select_order(seg, ic='aic', maxlag=maxlag)

Running import statsmodels.api as sm; sm.show_versions() raise the following error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In [228], line 1
----> 1 import statsmodels.api as sm
      2 sm.show_versions()

File ~\anaconda3\envs\oop_test\lib\site-packages\statsmodels\api.py:124
    122 from .tools.tools import add_constant, categorical
    123 from .tools.web import webdoc
--> 124 from .tsa import api as tsa
    125 from ._version import get_versions
    127 __version__ = get_versions()["version"]

File ~\anaconda3\envs\oop_test\lib\site-packages\statsmodels\tsa\api.py:74
     72 from .base import datetools
     73 from .exponential_smoothing.ets import ETSModel
---> 74 from .filters import api as filters, bk_filter, cf_filter, hp_filter
     75 from .forecasting.stl import STLForecast
     76 from .holtwinters import ExponentialSmoothing, Holt, SimpleExpSmoothing

File ~\anaconda3\envs\oop_test\lib\site-packages\statsmodels\tsa\filters\api.py:6
      4 from .hp_filter import hpfilter
      5 from .cf_filter import cffilter
----> 6 from .filtertools import miso_lfilter, convolution_filter, recursive_filter

File ~\anaconda3\envs\oop_test\lib\site-packages\statsmodels\tsa\filters\filtertools.py:18
     16 import scipy.fftpack as fft
     17 from scipy import signal
---> 18 from scipy.signal.signaltools import _centered as trim_centered
     20 from statsmodels.tools.validation import array_like, PandasWrapper
     22 def _pad_nans(x, head=None, tail=None):

ImportError: cannot import name '_centered' from 'scipy.signal.signaltools' (C:\Users\voodo\anaconda3\envs\oop_test\lib\site-packages\scipy\signal\signaltools.py)
bashtage commented 1 year ago

Your scipy is too new. You need to downgrade it to something earlier.

ImportError: cannot import name '_centered' from 'scipy.signal.signaltools' (C:\Users\voodo\anaconda3\envs\oop_test\lib\site-packages\scipy\signal\signaltools.py)
bashtage commented 1 year ago

You might also need to downgrade your pandas.

matteogabba commented 1 year ago

Can you please suggest which versions should I use?

bashtage commented 1 year ago

1.7.x seems to be the latest that has that attribute.

bashtage commented 1 year ago

You don't have the statsmodels you think you have. This is not an issue in 0.13.5. You should upgrade to 0.13.5 which works with both of these (pandas and scipy).

matteogabba commented 1 year ago

OK. If I run conda list it indicates the latest version. What is the reason of it? I will anyway try to reinstall a fresh virtenv. I will keep you updated. Thanks!

bashtage commented 1 year ago

Hard to say, but there is a try, except ImportError in the 0.13.x branch, and we test against these versions of pandas and scipy.