mito_genes and ValueError Traceback (most recent call last)
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
mito_genes = adata.var_names.str.startswith('MT-')
adata.obs['percent_mito'] = np.sum(adata[:, mito_genes].X, axis=1).A1 / np.sum(adata.X, axis=1).A1
adata.obs['n_counts'] = adata.X.sum(axis=1).A1
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-31-4b64d0e9fd7f> in <module>
2 # for each cell compute fraction of counts in mito genes vs. all genes
3 # the `.A1` is only necessary as X is sparse (to transform to a dense array after summing)
----> 4 adata.obs['percent_mito'] = np.sum(adata[:, mito_genes].X, axis=1).A1 / np.sum(adata.X, axis=1).A1
5 # add the total counts per cell as observations-annotation to adata
6 adata.obs['n_counts'] = adata.X.sum(axis=1).A1
c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in __getitem__(self, index)
1297 def __getitem__(self, index: Index) -> 'AnnData':
1298 """Returns a sliced view of the object."""
-> 1299 return self._getitem_view(index)
1300
1301 def _getitem_view(self, index: Index) -> 'AnnData':
c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in _getitem_view(self, index)
1300
1301 def _getitem_view(self, index: Index) -> 'AnnData':
-> 1302 oidx, vidx = self._normalize_indices(index)
1303 return AnnData(self, oidx=oidx, vidx=vidx, asview=True)
1304
c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in _normalize_indices(self, index)
1277 obs, var = super()._unpack_index(index)
1278 obs = _normalize_index(obs, self.obs_names)
-> 1279 var = _normalize_index(var, self.var_names)
1280 return obs, var
1281
c:\users\gsy\miniconda3\second\lib\site-packages\anndata\base.py in _normalize_index(index, names)
264 # incredibly faster one
265 positions = pd.Series(index=names, data=range(len(names)))
--> 266 positions = positions[index]
267 if positions.isnull().values.any():
268 raise KeyError(
c:\users\gsy\miniconda3\second\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
906 key = list(key)
907
--> 908 if com.is_bool_indexer(key):
909 key = check_bool_indexer(self.index, key)
910
c:\users\gsy\miniconda3\second\lib\site-packages\pandas\core\common.py in is_bool_indexer(key)
122 if not lib.is_bool_array(key):
123 if isna(key).any():
--> 124 raise ValueError(na_msg)
125 return False
126 return True
ValueError: cannot index with vector containing NA / NaN values
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the notebook expression shown in the report and start at anndata/base.py in _normalize_indices and _normalize_index, where the traceback reaches pandas Series indexing. Check the reported boolean mask and its variable names for the source of the failure; done should include a confirmed cause and a regression test or documented resolution, though the issue does not specify the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100