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

AttributeError: 'Series' object has no attribute 'nonzero' in sc.tl.filter_rank_genes_groups #3443

Open
2 of 3 tasks
niuniudevp opened this issue Jan 19, 2025 · 1 comment
Labels
Needs info❔ More information needed

Comments

@niuniudevp
Copy link

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

I get this error when running sc.tl.filter_rank_genes_groups

Minimal code sample

sc.tl.filter_rank_genes_groups(
    adata,
    min_in_group_fraction=0.2,
    max_out_group_fraction=0.2,
    key="dea_leiden_1",
    key_added="dea_leiden_1_filtered"
)

Error output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[/tmp/ipykernel_570417/3103778943.py](http://127.0.0.1:9999/tmp/ipykernel_570417/3103778943.py) in ?()
----> 1 sc.tl.filter_rank_genes_groups(
      2     adata,
      3     min_in_group_fraction=0.2,
      4     max_out_group_fraction=0.2,

[~/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/legacy_api_wrap/__init__.py](http://127.0.0.1:9999/lab/tree/scRNA-Learn/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/legacy_api_wrap/__init__.py) in ?(*args_all, **kw)
     79         @wraps(fn)
     80         def fn_compatible(*args_all: P.args, **kw: P.kwargs) -> R:
     81             if len(args_all) <= n_positional:
---> 82                 return fn(*args_all, **kw)
     83 
     84             args_pos: P.args
     85             args_pos, args_rest = args_all[:n_positional], args_all[n_positional:]

[~/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/scanpy/tools/_rank_genes_groups.py](http://127.0.0.1:9999/lab/tree/scRNA-Learn/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/scanpy/tools/_rank_genes_groups.py) in ?(adata, key, groupby, use_raw, key_added, min_in_group_fraction, min_fold_change, max_out_group_fraction, compare_abs)
    853             fraction_out_cluster_matrix.loc[:, cluster] = (
    854                 adata.uns[key]['pts_rest'][cluster].loc[var_names].values
    855             )
    856         else:
--> 857             fraction_in_cluster_matrix.loc[:, cluster] = _calc_frac(X_in)
    858             fraction_out_cluster_matrix.loc[:, cluster] = _calc_frac(X_out)
    859 
    860         if not use_logfolds:

[~/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/scipy/sparse/_index.py](http://127.0.0.1:9999/lab/tree/scRNA-Learn/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/scipy/sparse/_index.py) in ?(self, key)
     29     def __getitem__(self, key):
---> 30         index, new_shape = self._validate_indices(key)
     31 
     32         # 1D array
     33         if len(index) == 1:

[~/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/scipy/sparse/_index.py](http://127.0.0.1:9999/lab/tree/scRNA-Learn/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/scipy/sparse/_index.py) in ?(self, key)
    265                 if ix.shape != mid_shape:
    266                     raise IndexError(
    267                         f"bool index {i} has shape {mid_shape} instead of {ix.shape}"
    268                     )
--> 269                 index.extend(ix.nonzero())
    270                 array_indices.extend(range(index_ndim, tmp_ndim))
    271                 index_ndim = tmp_ndim
    272             else:  # dense array

[~/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/pandas/core/generic.py](http://127.0.0.1:9999/lab/tree/scRNA-Learn/miniforge3/envs/scRNA-py/lib/python3.10/site-packages/pandas/core/generic.py) in ?(self, name)
   6295         and index are copied). Any changes to the data of the original
   6296         will be reflected in the shallow copy (and vice versa).
   6297 
   6298         Parameters
-> 6299         ----------
   6300         deep : bool, default True
   6301             Make a deep copy, including a copy of the data and the indices.
   6302             With ``deep=False`` neither the indices nor the data are copied.

AttributeError: 'Series' object has no attribute 'nonzero'

Versions

-----
anndata     0.11.3
scanpy      1.10.4
-----
PIL                 11.1.0
anndata2ri          1.3.2
asttokens           NA
celltypist          1.6.3
certifi             2024.12.14
charset_normalizer  3.4.1
colorama            0.4.6
comm                0.2.2
cycler              0.12.1
cython_runtime      NA
dateutil            2.9.0.post0
debugpy             1.8.12
decorator           5.1.1
exceptiongroup      1.2.2
executing           2.1.0
h5py                3.12.1
idna                3.10
igraph              0.11.8
ipykernel           6.29.5
jedi                0.19.2
jinja2              3.1.5
joblib              1.4.2
kiwisolver          1.4.7
legacy_api_wrap     NA
leidenalg           0.10.2
llvmlite            0.43.0
markupsafe          3.0.2
matplotlib          3.10.0
matplotlib_inline   0.1.7
mpl_toolkits        NA
natsort             8.4.0
numba               0.60.0
numpy               2.0.2
packaging           24.2
pandas              2.2.3
parso               0.8.4
patsy               1.0.1
pickleshare         0.7.5
platformdirs        4.3.6
prompt_toolkit      3.0.48
psutil              6.1.1
pure_eval           0.2.3
pydev_ipython       NA
pydevconsole        NA
pydevd              3.2.3
pydevd_file_utils   NA
pydevd_plugins      NA
pydevd_tracing      NA
pygments            2.19.1
pynndescent         0.5.13
pyparsing           3.2.1
pytz                2024.1
requests            2.32.3
rpy2                3.5.17
scipy               1.15.1
seaborn             0.13.2
session_info        1.0.0
six                 1.17.0
sklearn             1.6.1
stack_data          0.6.3
statsmodels         0.14.4
texttable           1.7.0
threadpoolctl       3.5.0
tornado             6.4.2
tqdm                4.67.1
traitlets           5.14.3
typing_extensions   NA
tzlocal             NA
umap                0.5.7
urllib3             2.3.0
wcwidth             0.2.13
zmq                 26.2.0
-----
IPython             8.31.0
jupyter_client      8.6.3
jupyter_core        5.7.2
-----
Python 3.10.0 | packaged by conda-forge | (default, Nov 20 2021, 02:24:10) [GCC 9.4.0]
Linux-5.15.0-127-generic-x86_64-with-glibc2.31
-----
Session information updated at 2025-01-19 04:02
@niuniudevp niuniudevp added the Triage 🩺 This issue needs to be triaged by a maintainer label Jan 19, 2025
@flying-sheep flying-sheep added Needs info❔ More information needed and removed Triage 🩺 This issue needs to be triaged by a maintainer labels Jan 20, 2025
@flying-sheep
Copy link
Member

Hi, can you please make this reproducible? If I run

sc.tl.filter_rank_genes_groups(adata, ...)

I get: NameError: name 'adata' is not defined

Please give us the code to create adata and if that code refers to some file on your disk, upload that file and also give us the link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs info❔ More information needed
Projects
None yet
Development

No branches or pull requests

2 participants