module 'numpy' has no attribute 'asscalar'
srkim opened this issue · 16 comments
Getting the above error when importing riskfolio. This is using Numpy 1.24.2.
which version of Riskfolio-Lib ?
I'm using version 4.03.
I think you must uninstall and reinstall because I removed np.asscalar from all code when numpy gave the deprecation warning on that function.
odd, tried uninstall and reinstall and still getting the error on import.
import riskfolio.Portfolio as pf
No, now is just import riskfolio as rp, import riskfolio.portfolio as pf is from very old versions
tried import riskfolio as rp and still get the Numpy error.
Which is your Python version?
I did double check after uninstalling and it gave me a no module not found error. Reinstalled and tried to import with import riskfolio as rp and get the numpy error.
Python version 3.9.6
on Mac M1 version 13.2.1
Are you using anaconda ?
no, not using anaconda.
Use anaconda, for scientific python use anaconda at least on Mac. I also have a M1 and I don't have problems. But install rosetta and download the normal version of anaconda, not the ARM version.
I'll try anaconda on a test machine, but in the interim I thought I'd share the following.
File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/astropy/units/quantity_helper/function_helpers.py:116, in
108 UNSUPPORTED_FUNCTIONS |= {np.linalg.slogdet}
110 # The following are not just unsupported, but so unlikely to be thought
111 # to be supported that we ignore them in testing. (Kept in a separate
112 # variable so that we can check consistency in the test routine -
113 # test_quantity_non_ufuncs.py)
114 IGNORED_FUNCTIONS = {
115 # Deprecated
--> 116 np.asscalar, np.alen,
117 # I/O - useless for Quantity, since no way to store the unit.
118 np.save, np.savez, np.savetxt, np.savez_compressed,
119 # Polynomials
120 np.poly, np.polyadd, np.polyder, np.polydiv, np.polyfit, np.polyint,
121 np.polymul, np.polysub, np.polyval, np.roots, np.vander}
122 if NUMPY_LT_1_20:
123 # financial
124 IGNORED_FUNCTIONS |= {np.fv, np.ipmt, np.irr, np.mirr, np.nper,
125 np.npv, np.pmt, np.ppmt, np.pv, np.rate}
As I told you, if you look on the code, Riskfolio-Lib doesn't use np.asscalar. It's a problem with your Python configuration. If you don't use a scientific Python distribution it's not a Riskfolio-Lib issue.
Install new version