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

ValueError: could not convert integer scalar #88

Closed
alexlenail opened this issue Jan 9, 2023 · 3 comments
Closed

ValueError: could not convert integer scalar #88

alexlenail opened this issue Jan 9, 2023 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@alexlenail
Copy link

File ~/.conda/envs/py39/lib/python3.9/site-packages/muon/_atac/preproc.py:77, in tfidf(data, log_tf, log_idf, log_tfidf, scale_factor)
     74 if log_tfidf:
     75     tf_idf = np.log1p(tf_idf)
---> 77 adata.X = np.nan_to_num(tf_idf, 0)

File ~/.conda/envs/py39/lib/python3.9/site-packages/anndata/_core/anndata.py:688, in AnnData.X(self, value)
    684     if sparse.issparse(self._adata_ref._X) and isinstance(
    685         value, np.ndarray
    686     ):
    687         value = sparse.coo_matrix(value)
--> 688     self._adata_ref._X[oidx, vidx] = value
    689 else:
    690     self._X = value

File ~/.conda/envs/py39/lib/python3.9/site-packages/scipy/sparse/_index.py:137, in IndexMixin.__setitem__(self, key, x)
    135     x = x.tocoo(copy=True)
    136     x.sum_duplicates()
--> 137     self._set_arrayXarray_sparse(i, j, x)
    138 else:
    139     # Make x and i into the same shape
    140     x = np.asarray(x, dtype=self.dtype)

File ~/.conda/envs/py39/lib/python3.9/site-packages/scipy/sparse/_compressed.py:827, in _cs_matrix._set_arrayXarray_sparse(self, row, col, x)
    825 def _set_arrayXarray_sparse(self, row, col, x):
    826     # clear entries that will be overwritten
--> 827     self._zero_many(*self._swap((row, col)))
    829     M, N = row.shape  # matches col.shape
    830     broadcast_row = M != 1 and x.shape[0] == 1

File ~/.conda/envs/py39/lib/python3.9/site-packages/scipy/sparse/_compressed.py:947, in _cs_matrix._zero_many(self, i, j)
    945 n_samples = len(i)
    946 offsets = np.empty(n_samples, dtype=self.indices.dtype)
--> 947 ret = csr_sample_offsets(M, N, self.indptr, self.indices, n_samples,
    948                          i, j, offsets)
    949 if ret == 1:
    950     # rinse and repeat
    951     self.sum_duplicates()

ValueError: could not convert integer scalar

Saw scverse/anndata#339

Trying .copy()

If that works, shouldn't muon catch this error rather than computing the entire tf_idf matrix before failing?

@alexlenail alexlenail added the bug Something isn't working label Jan 9, 2023
@gtca
Copy link
Collaborator

gtca commented Jan 9, 2023

Thanks, @alexlenail!

Do you know how to reproduce this error? Is the modified modality a view?

@alexlenail
Copy link
Author

hippo_atac = adata_atac[adata_atac.obs.index.isin(hippo_cells)]
ac.pp.tfidf(hippo_atac)

==> ValueError: could not convert integer scalar

hippo_atac = adata_atac[adata_atac.obs.index.isin(hippo_cells)].copy()
ac.pp.tfidf(hippo_atac)

==> works

@gtca
Copy link
Collaborator

gtca commented Jan 18, 2023

I believe this is an issue that this particular preprocessing method doesn't handle views correctly. By convention, it should copy the data.
I'll mark this to be fixed for the next release, thank you!

@gtca gtca added this to the v0.1.3 milestone Jan 18, 2023
@gtca gtca closed this as completed in b835916 Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants