question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'tuple' object has no attribute 'tocsr'

See original GitHub issue

‘tuple’ object has no attribute ‘tocsr’

...
# neighborhood graph of cells (determine optimal number of PCs here)
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30)
# compute UMAP
sc.tl.umap(adata)
# tSNE
tsne = TSNE( n_jobs=20 )
adata.obsm['X_tsne'] = tsne.fit_transform( adata.X )
adata.write( f_anndata_path )
computing neighbors
    using 'X_pca' with n_pcs = 30
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-38-e2dd1fe70ab9> in <module>
      6 sc.settings.n_jobs = 15
      7 with parallel_backend('threading', n_jobs=20):
----> 8     sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30)
      9 
     10 #sc.settings.n_jobs = 15

~/miniconda3/envs/scanpy/lib/python3.6/site-packages/scanpy/neighbors/__init__.py in neighbors(adata, n_neighbors, n_pcs, use_rep, knn, random_state, method, metric, metric_kwds, copy)
     93         n_neighbors=n_neighbors, knn=knn, n_pcs=n_pcs, use_rep=use_rep,
     94         method=method, metric=metric, metric_kwds=metric_kwds,
---> 95         random_state=random_state,
     96     )
     97     adata.uns['neighbors'] = {}

~/miniconda3/envs/scanpy/lib/python3.6/site-packages/scanpy/neighbors/__init__.py in compute_neighbors(self, n_neighbors, knn, n_pcs, use_rep, method, random_state, write_knn_indices, metric, metric_kwds)
    681                 knn_distances,
    682                 self._adata.shape[0],
--> 683                 self.n_neighbors,
    684             )
    685         # overwrite the umap connectivities if method is 'gauss'

~/miniconda3/envs/scanpy/lib/python3.6/site-packages/scanpy/neighbors/__init__.py in compute_connectivities_umap(knn_indices, knn_dists, n_obs, n_neighbors, set_op_mix_ratio, local_connectivity)
    322     distances = get_sparse_matrix_from_indices_distances_umap(knn_indices, knn_dists, n_obs, n_neighbors)
    323 
--> 324     return distances, connectivities.tocsr()
    325 
    326 

AttributeError: 'tuple' object has no attribute 'tocsr'

Versions:

scanpy==1.4.4.post1 anndata==0.6.22.post1 umap==0.4.0 numpy==1.18.1 scipy==1.4.1 pandas==1.0.3 scikit-learn==0.22.2.post1 statsmodels==0.11.1 python-igraph==0.8.0 louvain==0.6.1

… Could you please help me resolve it? I looked up older issues but could not find solution to this. Thank you very much

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Flopecommented, May 8, 2021

I am getting this error when I run scanpy.pp.neighbors(adata) As far as I know, I have the latest packages mentioned here. anndata 0.7.6 pypi_0 pypi louvain 0.7.0 py38h9dedd22_1 conda-forge pandas 1.1.3 py38hb1e8313_0 python-igraph 0.9.1 py38h3dab7cd_0 conda-forge scanpy 1.7.2 pypi_0 pypi scikit-learn 0.23.2 py38h959d312_0 scipy 1.6.3 py38h431c0a8_0 conda-forge statsmodels 0.12.0 py38haf1e3a3_0 umap-learn 0.5.1 py38h50d1736_0 conda-forge

Is there probably another package that is outdated?

EDIT: Not sure what module I updated but now it works. I use ‘conda update --all’ and others to do that.

thanks

0reactions
Ahmed-fubcommented, Jun 13, 2021

I face the same problem. However I used latest version </scanpy==1.4.6 anndata==0.7.4 umap==0.5.1 numpy==1.20.3 scipy==1.6.3 pandas==1.2.4 scikit-learn==0.22.2.post1 statsmodels==0.11.1 python-igraph==0.8.2 , bbknn : 1.5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

'tuple' object has no attribute 'tocsr' · Issue #1154 - GitHub
'tuple' object has no attribute 'tocsr' ... # neighborhood graph of cells (determine optimal number of PCs here) sc.pp.neighbors(adata, ...
Read more >
'tuple' object has no attribute 'type' upon importing tensorflow ...
python 3. x - AttributeError: 'tuple' object has no attribute 'type' upon importing tensorflow - Stack Overflow. Stack Overflow for Teams – ...
Read more >
scipy.sparse.coo_matrix — SciPy v1.9.3 Manual
COO is a fast format for constructing sparse matrices · Once a matrix has been constructed, convert to CSR or CSC format for...
Read more >
Python AttributeError: 'tuple' object has no attribute
AttributeError : 'tuple' object has no attribute. Learn Data Science with. This error occurs when attempting to access the values of a tuple...
Read more >
tuple' object has no attribute 'tocsr' - 掘金
tuple ' object has no attribute 'tocsr'技术、学习、经验文章掘金开发者社区搜索结果。掘金是一个帮助开发者成长的社区,tuple' object has no attribute 'tocsr'技术 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found