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

KeyError: 'False: boolean label can not be used without a boolean index' #225

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

Comments

@zhoushican
Copy link

%%time
adata=ov.pp.qc(adata,
              tresh={'mito_perc': 0.2, 'nUMIs': 500, 'detected_genes': 250},
              batch_key=None)
adata

When I run this line of code, the following error occurs:

{
	"name": "KeyError",
	"message": "'False: boolean label can not be used without a boolean index'",
	"stack": "---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File <timed exec>:1

File ~/mambaforge/envs/omicverse_gpuOne/lib/python3.10/site-packages/omicverse/pp/_qc.py:195, in qc(adata, **kwargs)
    193 if settings.mode == 'gpu':
    194     print('GPU mode activated')
--> 195     return qc_gpu(adata,**kwargs)
    196 else:
    197     print('CPU mode activated')

File ~/mambaforge/envs/omicverse_gpuOne/lib/python3.10/site-packages/omicverse/pp/_qc.py:464, in qc_gpu(adata, mode, min_cells, min_genes, nmads, max_cells_ratio, max_genes_ratio, batch_key, doublets, doublets_method, path_viz, tresh, mt_startswith, mt_genes)
    462 # QC plot
    463 QC_test = (adata.obs['passing_mt']) & (adata.obs['passing_nUMIs']) & (adata.obs['passing_ngenes'])
--> 464 removed = QC_test.loc[lambda x : x is False]
    465 removed_cells.extend(list(removed.index.values))
    466 print(f'Total cell filtered out with this last --mode {mode} QC (and its chosen options): \\
    467 {n1-np.sum(QC_test)}')

File ~/mambaforge/envs/omicverse_gpuOne/lib/python3.10/site-packages/pandas/core/indexing.py:1073, in _LocationIndexer.__getitem__(self, key)
   1070 axis = self.axis or 0
   1072 maybe_callable = com.apply_if_callable(key, self.obj)
-> 1073 return self._getitem_axis(maybe_callable, axis=axis)

File ~/mambaforge/envs/omicverse_gpuOne/lib/python3.10/site-packages/pandas/core/indexing.py:1311, in _LocIndexer._getitem_axis(self, key, axis)
   1308         return self.obj.iloc[tuple(indexer)]
   1310 # fall thru to straight lookup
-> 1311 self._validate_key(key, axis)
   1312 return self._get_label(key, axis=axis)

File ~/mambaforge/envs/omicverse_gpuOne/lib/python3.10/site-packages/pandas/core/indexing.py:1118, in _LocIndexer._validate_key(self, key, axis)
   1108 @doc(_LocationIndexer._validate_key)
   1109 def _validate_key(self, key, axis: int):
   1110     # valid for a collection of labels (we check their presence later)
   1111     # slice of labels (where start-end in labels)
   1112     # slice of integers (only if in the labels)
   1113     # boolean not in slice and with boolean index
   1114     if isinstance(key, bool) and not (
   1115         is_bool_dtype(self.obj._get_axis(axis))
   1116         or self.obj._get_axis(axis).dtype.name == \"boolean\"
   1117     ):
-> 1118         raise KeyError(
   1119             f\"{key}: boolean label can not be used without a boolean index\"
   1120         )
   1122     if isinstance(key, slice) and (
   1123         isinstance(key.start, bool) or isinstance(key.stop, bool)
   1124     ):
   1125         raise TypeError(f\"{key}: boolean values can not be used in a slice\")

KeyError: 'False: boolean label can not be used without a boolean index'"
}
@HendricksJudy
Copy link
Collaborator

Sir, after testing the specific script

Fix the KeyError in the qc_gpu function by correctly handling boolean labels.

  • Update line 464 in qc_gpu function in omicverse/pp/_qc.py to use a boolean index instead of a boolean label.

    • Change removed = QC_test.loc[lambda x : x is False] to removed = QC_test.loc[QC_test == False].

    You may apply this to fix until the next update to solve this ERROR

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