Unable to import functions from scipy module.
Gives error :
from scipy.signal.signaltools import _centered
Cannot import name '_centered' from 'scipy.signal.signaltools'
scipy.__version__
1.8.0
I encountered the same problem while using statsmodels~=0.12.x
. Increasing the statsmodels package to version 0.13.2
, this import issue is resolved.
UPDATE with more notes:
statsmodels==0.12.2
which is dependent on scipy
scipy==1.8.0
- 2022-02-05
from statsmodels.tsa.seasonal import seasonal_decompose
File "/usr/local/lib/python3.8/site-packages/statsmodels/tsa/seasonal.py", line 12, in <module>
from statsmodels.tsa.filters.filtertools import convolution_filter
File "/usr/local/lib/python3.8/site-packages/statsmodels/tsa/filters/filtertools.py", line 18, in <module>
from scipy.signal.signaltools import _centered as trim_centered
ImportError: cannot import name '_centered' from 'scipy.signal.signaltools' (/usr/local/lib/python3.8/site-packages/scipy/signal/signaltools.py)
after:
statsmodels
to the latest version available 0.13.2
release 2022-02-08, it worksIf you are not using statsmodels
but other package which is dependent on scipy
, have a look if there is newer version available (after the release of scipy
to v.1.8.0
)
If you need to use that specific version of statsmodels 0.12.x with scipy 1.8.0 I have the following hack. Basically it just re-publishes the existing (but private) _centered function as a public attribute to the module already imported in RAM.
It is a workaround, and if you can simply upgrade your dependencies to the latest versions. Only use this if you are forced to use those specific versions.
import scipy.signal.signaltools
def _centered(arr, newsize):
# Return the center newsize portion of the array.
newsize = np.asarray(newsize)
currsize = np.array(arr.shape)
startind = (currsize - newsize) // 2
endind = startind + newsize
myslice = [slice(startind[k], endind[k]) for k in range(len(endind))]
return arr[tuple(myslice)]
scipy.signal.signaltools._centered = _centered
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With