Skip to content

KeyError: 'clusters' #224

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

Open
enzeas opened this issue Dec 10, 2024 · 1 comment
Open

KeyError: 'clusters' #224

enzeas opened this issue Dec 10, 2024 · 1 comment

Comments

@enzeas
Copy link

enzeas commented Dec 10, 2024

Describe the bug

when follow the tutorial bulk2single, the function ov.bulk2single.bulk2single_plot_cellprop raise a KeyError: 'clusters'.

To Reproduce

command:
ov.bulk2single.bulk2single_plot_cellprop(generate_adata,celltype_key='clusters')

errors:
----> 1 ov.bulk2single.bulk2single_plot_cellprop(generate_adata,celltype_key='clusters')
File /data/miniforge3/envs/ov-gpu/lib/python3.10/site-packages/omicverse/bulk2single/_utils.py:69, in bulk2single_plot_cellprop(generate_single_data, celltype_key, figsize)
67 key_name=list(generate_single_data.obs[celltype_key].cat.categories)
68 ct_name = list(ct_stat.index)
---> 69 ct_num = list(ct_stat[celltype_key])
70 if '{}_colors'.format(celltype_key) in generate_single_data.uns.keys():
71 color=generate_single_data.uns['{}_colors'.format(celltype_key)]
File /data/miniforge3/envs/ov-gpu/lib/python3.10/site-packages/pandas/core/frame.py:4102, in DataFrame.getitem(self, key)
4100 if self.columns.nlevels > 1:
4101 return self._getitem_multilevel(key)
-> 4102 indexer = self.columns.get_loc(key)
4103 if is_integer(indexer):
4104 indexer = [indexer]
File /data/miniforge3/envs/ov-gpu/lib/python3.10/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
3807 if isinstance(casted_key, slice) or (
3808 isinstance(casted_key, abc.Iterable)
3809 and any(isinstance(x, slice) for x in casted_key)
3810 ):
3811 raise InvalidIndexError(key)
-> 3812 raise KeyError(key) from err
3813 except TypeError:
3814 # If we have a listlike key, _check_indexing_error will raise
3815 # InvalidIndexError. Otherwise we fall through and re-raise
3816 # the TypeError.
3817 self._check_indexing_error(key)

KeyError: 'clusters'

Additional context
when use the pandas function value_counts(), the dataframe has a column named 'count' , and this key should be 'count', not 'clusters',
微信截图_20241210143148

@HendricksJudy
Copy link
Collaborator

Sir, after testing the specific script

Fix KeyError: 'clusters' in bulk2single_plot_cellprop function

  • Change ct_stat[celltype_key] to ct_stat['count'] at line 69 in omicverse/bulk2single/_utils.py to correctly reference the 'count' column created by the value_counts() method.

You may apply this change to fix until the this error is solved by the next update.

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