I was analysing some scRNA-seq data from GSE214966 when I encountered a problem in executing cnv_score()
function from infercnvpy
package. It consistenly raises a AttributeError: 'Series' object has no attribute 'nonzero'.
I also tried reproducing the example from their website tutorial (https://infercnvpy.readthedocs.io/en/latest/notebooks/tutorial_3k.html) but it raises the same error. That probably mean that the problem it's on my end but I can't figure out what's wrong.
I tried reinstalling all packages and python as well but nothing worked out. The error suggests that the problem is that Pandas.Series
doesn't have a attribute such as nonzero
, which it doesn't. But then I don't know what's wrong or how to solve this problem since it is a function from a package.
Can anybody help me with this?
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9248\2255080222.py in ?()
1 import infercnvpy as cnv
----> 2 cnv.tl.cnv_score(adata, groupby="leiden")
d:\Datos de usuario\Desktop\Single Cell Analysis\Glioblastoma (GSE214966)\Glioblastoma-GSE214966\.venv\Lib\site-packages\infercnvpy\tl\_scores.py in ?(adata, groupby, use_rep, key_added, inplace, obs_key)
61 groupby = obs_key
62
63 if groupby not in adata.obs.columns and groupby == "cnv_leiden":
64 raise ValueError("`cnv_leiden` not found in `adata.obs`. Did you run `tl.leiden`?")
---> 65 cluster_score = {
66 cluster: np.mean(np.abs(adata.obsm[f"X_{use_rep}"][adata.obs[groupby] == cluster, :]))
67 for cluster in adata.obs[groupby].unique()
68 }
d:\Datos de usuario\Desktop\Single Cell Analysis\Glioblastoma (GSE214966)\Glioblastoma-GSE214966\.venv\Lib\site-packages\scipy\sparse\_index.py in ?(self, key)
29 def __getitem__(self, key):
---> 30 index, new_shape = self._validate_indices(key)
31
32 # 1D array
33 if len(index) == 1:
d:\Datos de usuario\Desktop\Single Cell Analysis\Glioblastoma (GSE214966)\Glioblastoma-GSE214966\.venv\Lib\site-packages\scipy\sparse\_index.py in ?(self, key)
265 if ix.shape != mid_shape:
266 raise IndexError(
267 f"bool index {i} has shape {mid_shape} instead of {ix.shape}"
268 )
--> 269 index.extend(ix.nonzero())
270 array_indices.extend(range(index_ndim, tmp_ndim))
271 index_ndim = tmp_ndim
272 else: # dense array
d:\Datos de usuario\Desktop\Single Cell Analysis\Glioblastoma (GSE214966)\Glioblastoma-GSE214966\.venv\Lib\site-packages\pandas\core\generic.py in ?(self, name)
6295 and name not in self._accessors
6296 and self._info_axis._can_hold_identifiers_and_holds_name(name)
6297 ):
6298 return self[name]
-> 6299 return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'nonzero'
Session_info
-----
anndata 0.11.3
infercnvpy 0.5.0
matplotlib 3.10.0
numpy 1.26.4
openpyxl 3.1.5
pandas 2.2.3
scanpy 1.10.4
scipy 1.15.1
session_info 1.0.0
sklearn 1.6.1
-----
PIL 11.1.0
asttokens NA
attr 24.3.0
attrs 24.3.0
cairo 1.27.0
cattr NA
cattrs NA
certifi 2024.12.14
charset_normalizer 3.4.1
colorama 0.4.6
comm 0.2.2
cycler 0.12.1
...
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)]
Windows-10-10.0.19045-SP0
-----
Session information updated at 2025-01-16 16:27
A similar issue was raised on https://github.com/chanzuckerberg/single-cell-curation/issues/1165. Seems to be a bug with scipy version >= 1.15.0. The user stated that rolling back to scipy version 1.14.1 fixes the issue. It's still an open bug issue on the repository.