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

Duplicates in index throw error during make_index_unique #1670

Open
lesolorzanov opened this issue Sep 11, 2024 · 1 comment
Open

Duplicates in index throw error during make_index_unique #1670

lesolorzanov opened this issue Sep 11, 2024 · 1 comment

Comments

@lesolorzanov
Copy link

My system: Ubuntu 23.10
Anndata version: '0.10.5.post1'

When dealing with anndata.var.index the function make_index_unique in utils, was constantly throwing a pandas related error:

pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects

By going into the utils file the error that appeared was

TypeError: 'Cannot setitem on a Categorical with a new category (X-1), set the categories first

It happened while attempting to remove the duplicates and creating a pd.Categorical in

values_dup = values[indices_dup]
and then attempting to add the tentative new name to a pd.Categorical without the categories which include the tentative new name.

In summary, when I change these lines to a more generic version, it solved the problem. Just wanted to share in case someone needs it

for example instead of values_dup = values[indices_dup] use values_dup = np.array(values[indices_dup])

and replace Values with a copy of itself but containing the right categories, like this:
values=pd.Categorical(values,categories=list(values.categories)+list(values_dup))

@flying-sheep
Copy link
Member

Hi, please use the issue templates instead of opening blank issues, they are there fore a reason.

Can you please create a minimal reproducible example that reproduces the problem with the newest anndata version (0.10.9 or 0.11.0rc1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants