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

Error in make_nhoods if the reduced dims are in pandas.DataFrame #34

Open
emdann opened this issue Mar 3, 2023 · 1 comment
Open

Error in make_nhoods if the reduced dims are in pandas.DataFrame #34

emdann opened this issue Mar 3, 2023 · 1 comment

Comments

@emdann
Copy link
Owner

emdann commented Mar 3, 2023

The error:

milo.make_nhoods(adata, prop=0.05)
InvalidIndexError: (array([    6,    14,    31,    32,    36,    41,    44,    45,    46,
        1226,  1893,  2742,  3122,  3475,  3494,  3578,  3588,  4416,
        4446,  5146,  5274,  5686,  6432,  6524,  7218,  7323,  8239,
        8945, 13048, 14444, 14774, 15035, 15580, 16304, 20604, 20842,
       21208, 21289, 21313, 21352, 23599], dtype=int32), slice(None, None, None))

The quick fix:

adata.obsm[adata.uns['neighbors']['use_rep']] = adata.obsm[adata.uns['neighbors']['use_rep']].values.copy()

Solution: convert X_dimred to array if it's a DataFrame

@james-cranley
Copy link

james-cranley commented Jun 24, 2023

thanks @emdann , i had this error today for the first time. I've used this milopy function in another conda env with no issues. is it something to do with pandas 2 (which was installed in the new env) that is causing this to be flagged as an error now?

and, for me unfortuantely the 'quick fix' code gave me:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[37], line 1
----> 1 adata.obsm[adata.uns['neighbors']['use_rep']] = adata.obsm[adata.uns['neighbors']['use_rep']].values.copy()

KeyError: 'use_rep'

I inspected adata.uns['neighbors']:

adata.uns['neighbors']

{'connectivities_key': 'connectivities',
 'distances_key': 'distances',
 'params': {'n_neighbors': 15,
  'method': 'umap',
  'random_state': 0,
  'metric': 'euclidean',
  'use_rep': 'X_scArches'}}

Anyway, this line of code did work for me as a quick fix adata.obsm[adata.uns['neighbors']['params']['use_rep']] = adata.obsm[adata.uns['neighbors']['params']['use_rep']].values.copy()

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

No branches or pull requests

2 participants