Closed MarwaneBourdim closed 2 months ago
Hi @MarwaneBourdim,
You can transform your matrix to a csr_matrix
for it to work properly:
from scipy.sparse import csr_matrix
adata.raw.X = csr_matrix(adata.raw.X)
Nonetheless, I think I fixed this isse in decoupler >= 1.6.0
, which version do you have installed?
Hi @PauBadiaM,
Thank you for your prompt response. I've got the latest version of decoupler, when I try your code snippet I get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[18], line 1
----> 1 adata.raw.X = csr_matrix(adata.raw.X)
AttributeError: can't set attribute 'X'
Nonetheless, I dont think that's where the problem is because when I look at:
adata.raw.X
It outputs:
<Compressed Sparse Row sparse matrix of dtype 'float32'
with 2238732 stored elements and shape (2638, 13714)>
However, if I try to look at its attribute A:
adata.raw.X.A
I get:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[20], line 1
----> 1 adata.raw.X.A
AttributeError: 'csr_matrix' object has no attribute 'A'
Like in the original error.
Do you think, it's a problem with scipy? I even went to check the list of attributes of scipy sparse matrices, "A" wasn't explicitly in it but it was an attribute of "numpy.matrix" which is a datatype I don't get the above error with. I guess sparse matrices are defined from numpy matrices and that this attribute is supposed to be heritable for scipy sparse matrices but not in my environment for some reason? It seems really strange.
Could be that you get this error because you store your counts values as a sparse matrix and not a sparse array? These two classes, even though they look the same have different properties. In general, in the scverse ecosystem people use arrays over matrices.
I get the same error with sparse arrays:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[26], line 3
1 import scipy as sp
----> 3 sp.sparse.csr_array(adata.raw.X).A
4 sp.sparse.csr_matrix(adata.raw.X).A
AttributeError: 'csr_array' object has no attribute 'A'
Ahh oh wow, apparently in the newer scipy
version they have deprecated the use of .A
(see https://github.com/scipy/scipy/issues/21049#issuecomment-2189757313).
I'll have to refactor some code but in the meantime you can downgrade scipy
to < 1.14.0
, thanks for reporting this!
Perfect thank you!
Hi,
When I try to reproduce the pathway activity inference vignette, I try to run:
And I get the following Attribute error:
Looking at the code, it makes sense to me since adata.raw.X is not of type np.matrix and doesn't have attribute "A". So I've tried to convert it with:
But when I do that I get this other error:
TypeError: matrix.sum() got an unexpected keyword argument 'keepdims'
In the meantime to circumvent it, I simply convert adata.raw to a pandas Dataframe like that :
I think it works this way, but I'd like to know what's wrong with the other way.
This problem happens in the following environment: