ValueError: cannot reindex from a duplicate axis
See original GitHub issueI’m trying to merge the loom file with my scanpy object using the following:
adata_velocity = scv.read('/home/ec2-user/velocyto/aggregate.loom', cache=False) scv.utils.merge(adata, adata_velocity)
But I get the following error:
`--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-35-7ce94ec7db71> in <module> 1 adata_velocity = scv.read(‘/home/ec2-user/velocyto/aggregate.loom’, cache=False) ----> 2 scv.utils.merge(adata, adata_velocity)
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/scvelo/read_load.py in merge(adata, ldata, copy) 134 same_vars = (len(_adata.var_names) == len(_ldata.var_names) and np.all(_adata.var_names == _ldata.var_names)) 135 if len(common_vars) > 0 and not same_vars: –> 136 _adata._inplace_subset_var(common_vars) 137 _ldata._inplace_subset_var(common_vars) 138
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/anndata/base.py in _inplace_subset_var(self, index)
1505 Same as adata = adata[:, index]
, but inplace.
1506 “”"
-> 1507 adata_subset = self[:, index].copy()
1508 self._init_as_actual(adata_subset, dtype=self._X.dtype)
1509
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/anndata/base.py in getitem(self, index) 1371 def getitem(self, index: Index) -> ‘AnnData’: 1372 “”“Returns a sliced view of the object.”“” -> 1373 return self._getitem_view(index) 1374 1375 def _getitem_view(self, index: Index) -> ‘AnnData’:
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/anndata/base.py in _getitem_view(self, index) 1374 1375 def _getitem_view(self, index: Index) -> ‘AnnData’: -> 1376 oidx, vidx = self._normalize_indices(index) 1377 return AnnData(self, oidx=oidx, vidx=vidx, asview=True) 1378
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/anndata/base.py in _normalize_indices(self, index) 1351 obs, var = unpack_index(index) 1352 obs = _normalize_index(obs, self.obs_names) -> 1353 var = _normalize_index(var, self.var_names) 1354 return obs, var 1355
~/anaconda3/envs/sc-tutorial/lib/python3.7/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 not_found = positions.index[positions.isnull().values]
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/series.py in getitem(self, key) 909 key = check_bool_indexer(self.index, key) 910 –> 911 return self._get_with(key) 912 913 def _get_with(self, key):
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/series.py in _get_with(self, key) 951 return self.loc[key] 952 –> 953 return self.reindex(key) 954 except Exception: 955 # [slice(0, 5, None)] will break if you convert to ndarray,
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/series.py in reindex(self, index, **kwargs) 3736 @Appender(generic.NDFrame.reindex.doc) 3737 def reindex(self, index=None, **kwargs): -> 3738 return super(Series, self).reindex(index=index, **kwargs) 3739 3740 def drop(self, labels=None, axis=0, index=None, columns=None,
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/generic.py in reindex(self, *args, **kwargs) 4354 # perform the reindex on the axes 4355 return self._reindex_axes(axes, level, limit, tolerance, method, -> 4356 fill_value, copy).finalize(self) 4357 4358 def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/generic.py in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy) 4372 obj = obj._reindex_with_indexers({axis: [new_index, indexer]}, 4373 fill_value=fill_value, -> 4374 copy=copy, allow_dups=False) 4375 4376 return obj
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/generic.py in _reindex_with_indexers(self, reindexers, fill_value, copy, allow_dups) 4488 fill_value=fill_value, 4489 allow_dups=allow_dups, -> 4490 copy=copy) 4491 4492 if copy and new_data is self._data:
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/internals/managers.py in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups, copy) 1222 # some axes don’t allow reindexing with dups 1223 if not allow_dups: -> 1224 self.axes[axis]._can_reindex(indexer) 1225 1226 if axis >= self.ndim:
~/anaconda3/envs/sc-tutorial/lib/python3.7/site-packages/pandas/core/indexes/base.py in _can_reindex(self, indexer) 3085 # trying to reindex on an axis with duplicates 3086 if not self.is_unique and len(indexer): -> 3087 raise ValueError(“cannot reindex from a duplicate axis”) 3088 3089 def reindex(self, target, method=None, level=None, limit=None,
ValueError: cannot reindex from a duplicate axis`
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
adata.var_names_make_unique()
is, in fact, called internally in the merge module.Did it work for you, @davidepisu?
After having assuring on some examples that the error mentioned is not reproducible anymore, I close this issue. Let me know, if still anything complains.