Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Received error 'csr_matrix' object has no attribute 'A' #357

Open
rr1964 opened this issue Jul 19, 2024 · 4 comments
Open

Received error 'csr_matrix' object has no attribute 'A' #357

rr1964 opened this issue Jul 19, 2024 · 4 comments

Comments

@rr1964
Copy link

rr1964 commented Jul 19, 2024

Environment is Python 3.11. In order to avoid the issues of #337 I uninstall scikit-sparse. However, this then presents a new error from line 81 of utils.py:

File [~/micromamba/envs/ml/lib/python3.11/site-packages/pygam/utils.py:81]

(http://localhost:8888/~/micromamba/envs/ml/lib/python3.11/site-packages/pygam/utils.py#line=80), in cholesky(A, sparse, verbose)

 78     warnings.warn(msg)
 80 if sp.sparse.issparse(A):
 81     A = A.A
 83 try:
 84     L = sp.linalg.cholesky(A, lower=False)

AttributeError: 'csr_matrix' object has no attribute 'A'

As it stands now, PyGAM is no longer usable for "newer" version of Python Scipy. (As far as I can tell, this fails on versions of Scipy going back several years).

@rr1964
Copy link
Author

rr1964 commented Jul 19, 2024

To fix this, I manually changed line 81 of utils.py to A = A.toarray(). You will also need to change lines 706 and 783 of pygam.py to use toarray() instead of the .A syntax. There may be more places as well, depending on which models you use. The broad fix is just to replace .A with toarray() everywhere you get that error.

@MMCMA
Copy link

MMCMA commented Aug 5, 2024

You can downgrade to scipy=1.13.1 to resolve the issue. I suspect it requires a new release to fix the dependency to scipy>1.14.0

@tylerdougan
Copy link

tylerdougan commented Oct 29, 2024

Another hack-y solution is a monkey patch:

import scipy.sparse

def to_array(self):
    return self.toarray()

scipy.sparse.spmatrix.A = property(to_array)

import pygam

ouslan added a commit to ouslan/BayesGAM that referenced this issue Dec 8, 2024
ouslan added a commit to ouslan/BayesGAM that referenced this issue Dec 8, 2024
@gagreene
Copy link

To fix this, I manually changed line 81 of utils.py to A = A.toarray(). You will also need to change lines 706 and 783 of pygam.py to use toarray() instead of the .A syntax. There may be more places as well, depending on which models you use. The broad fix is just to replace .A with toarray() everywhere you get that error.

I did the same. Running Python 3.12.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants