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.

ValueError: cannot reindex from a duplicate axis

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
VolkerBergencommented, Jun 27, 2019

adata.var_names_make_unique() is, in fact, called internally in the merge module.

Did it work for you, @davidepisu?

0reactions
VolkerBergencommented, Aug 22, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solve Pandas "ValueError: cannot reindex from a duplicate axis"
Apparently, the python error is the result of doing operations on a DataFrame that has duplicate index values. Operations that require unique ...
Read more >
What does `ValueError: cannot reindex from a duplicate axis ...
I am getting a ValueError: cannot reindex from a duplicate axis when I am trying to set an index to a certain value....
Read more >
ValueError: cannot reindex from a ... - Net-Informations.Com
The error "cannot reindex from a duplicate axis" usually generates when you concatenate, reindexing or resampling a DataFrame which the index has duplicate ......
Read more >
Using dataframe with duplicate index raises ValueError ...
Some seaborn functions generate an error ValueError: cannot reindex from a duplicate axis with such dataframes. lineplot , stripplot , swarmplot give such...
Read more >
Duplicate Labels — pandas 1.2.4 documentation
Some pandas methods ( Series.reindex() for example) just don't work with duplicates present. The output can't be determined, and so pandas raises.
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