You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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',
The text was updated successfully, but these errors were encountered:
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.
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',
The text was updated successfully, but these errors were encountered: