aertslab / pySCENIC

pySCENIC is a lightning-fast python implementation of the SCENIC pipeline (Single-Cell rEgulatory Network Inference and Clustering) which enables biologists to infer transcription factors, gene regulatory networks and cell types from single-cell RNA-seq data.
http://scenic.aertslab.org
GNU General Public License v3.0
443 stars 182 forks source link

[BUG] Numpy Object Deprecation Error #536

Closed Tripfantasy closed 7 months ago

Tripfantasy commented 7 months ago

Describe the bug When running pySCENIC CLI GRN step, the function is halted by an error which seems to be sourced by the use of a deprecated numpy alias "np.object0" in _type_info dictionary in numpy's init.py

Before I would be warned about a deprecated alias, but it wouldn't stop the function from completing entirely. I have manually changed the value as seen below, but I'm not sure if there is a different method of avoiding this? Thanks in advance!

Steps to reproduce the behavior

  1. Command run when the error occurred:

    pyscenic grn expression_mtx.loom tfs.txt --num_workers 20 --method grnboost2 --sparse -o adj.csv
  2. Error encountered:

    /home/dm2763/micromamba/envs/pyscenic/lib/python3.10/site-packages/pyscenic/transform.py:42: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
    ("Enrichment", COLUMN_NAME_ANNOTATION): np.object,
    Traceback (most recent call last):
    File "/home/dm2763/micromamba/envs/pyscenic/bin/pyscenic", line 5, in <module>
    from pyscenic.cli.pyscenic import main
    File "/home/dm2763/micromamba/envs/pyscenic/lib/python3.10/site-packages/pyscenic/cli/pyscenic.py", line 26, in <module>
    from pyscenic.prune import _prepare_client, find_features, prune2df
    File "/home/dm2763/micromamba/envs/pyscenic/lib/python3.10/site-packages/pyscenic/prune.py", line 27, in <module>
    from .transform import (
    File "/home/dm2763/micromamba/envs/pyscenic/lib/python3.10/site-packages/pyscenic/transform.py", line 42, in <module>
    ("Enrichment", COLUMN_NAME_ANNOTATION): np.object,
    File "/home/dm2763/micromamba/envs/pyscenic/lib/python3.10/site-packages/numpy/__init__.py", line 324, in __getattr__
    raise AttributeError(__former_attrs__[attr])
    AttributeError: module 'numpy' has no attribute 'object'.

Expected behavior When running grn on CLI, I expect it to load the expression matrix first, then prepare the dask graph. Once it loads, it should begin calculating adjacencies.

I also expect there to be a couple deprecation warnings, for example- the numpy.object deprecated alias warning, as well as a "NumbaDeprecationWarning: nopython keyword" warning. These warnings typically do not halt the function, but as mentioned before- the numpy one seems to as of this past week.

Please complete the following information:

name: pyscenic
channels:
- conda-forge
dependencies:
- _libgcc_mutex=0.1=conda_forge
- _openmp_mutex=4.5=2_gnu
- bzip2=1.0.8=hd590300_5
- ca-certificates=2024.2.2=hbcca054_0
- ld_impl_linux-64=2.40=h41732ed_0
- libffi=3.4.2=h7f98852_5
- libgcc-ng=13.2.0=h807b86a_5
- libgomp=13.2.0=h807b86a_5
- libnsl=2.0.1=hd590300_0
- libsqlite=3.41.2=h2797004_1
- libstdcxx-ng=13.2.0=h7e041cc_5
- libuuid=2.38.1=h0b41bf4_0
- libzlib=1.2.13=hd590300_5
- ncurses=6.4=h59595ed_2
- openssl=3.0.11=hd590300_0
- pip=23.3.2=pyhd8ed1ab_0
- python=3.10.9=he550d4f_0_cpython
- readline=8.2=h8228510_1
- setuptools=68.0.0=pyhd8ed1ab_0
- sqlite=3.41.2=h2c6b66d_1
- tk=8.6.12=h27826a3_0
- tzdata=2024a=h0c530f3_0
- wheel=0.41.2=pyhd8ed1ab_0
- xz=5.2.6=h166bdaf_0
- zlib=1.2.13=hd590300_5
- pip:
  - aiohttp==3.8.6
  - aiosignal==1.3.1
  - arboreto==0.1.6
  - async-timeout==4.0.3
  - attrs==23.1.0
  - bokeh==3.3.0
  - boltons==23.0.0
  - certifi==2023.7.22
  - cffi==1.16.0
  - charset-normalizer==3.3.0
  - click==8.1.7
  - cloudpickle==3.0.0
  - contourpy==1.1.1
  - ctxcore==0.2.0
  - cytoolz==0.12.2
  - dask==2023.10.0
  - dill==0.3.7
  - distributed==2023.10.0
  - frozendict==2.3.8
  - frozenlist==1.4.0
  - fsspec==2023.9.2
  - h5py==3.10.0
  - idna==3.4
  - importlib-metadata==6.8.0
  - interlap==0.2.7
  - Jinja2==3.1.2
  - joblib==1.3.2
  - llvmlite==0.41.1
  - locket==1.0.0
  - loompy==3.0.7
  - lz4==4.3.2
  - MarkupSafe==2.1.3
  - msgpack==1.0.7
  - MulticoreTSNE==0.1
  - multidict==6.0.4
  - multiprocessing-on-dill==3.5.0a4
  - networkx==3.1
  - numba==0.58.1
  - numexpr==2.8.7
  - numpy==1.26.1
  - numpy-groupies==0.10.2
  - packaging==23.2
  - pandas==2.1.1
  - partd==1.4.1
  - Pillow==10.1.0
  - psutil==5.9.6
  - pyarrow==13.0.0
  - pycparser==2.21
  - pynndescent==0.5.10
  - pyscenic==0.12.1
  - python-dateutil==2.8.2
  - pytz==2023.3.post1
  - PyYAML==6.0.1
  - requests==2.31.0
  - scikit-learn==1.3.1
  - scikit-misc==0.2.0
  - scipy==1.11.3
  - six==1.16.0
  - sortedcontainers==2.4.0
  - tbb==2021.10.0
  - tblib==2.0.0
  - threadpoolctl==3.2.0
  - toolz==0.12.0
  - tornado==6.3.3
  - tqdm==4.66.1
  - tzdata==2023.3
  - umap-learn==0.5.4
  - urllib3==2.0.7
  - xyzservices==2023.10.0
  - yarl==1.9.2
  - zict==3.0.0
  1. Temporary fix?
    • Change np.object0 to "object" in _type_info dictionary
    • Location:
      /micromamba/envs/pyscenic/lib/python3.10/site-packages/numpy/__init__.py", line 324
_type_info = [
        ("bool8", bool_, "np.bool_"),
        ("int0", intp, "np.intp"),
        ("uint0", uintp, "np.uintp"),
        ("str0", str_, "np.str_"),
        ("bytes0", bytes_, "np.bytes_"),
        ("void0", void, "np.void"),
        ("object", object_,
            "`np.object0` is a deprecated alias for `np.object_`. "
            "`object` can be used instead.  (Deprecated NumPy 1.24)")]
iamakhilverma commented 7 months ago

Facing the same issue:

AttributeError: module 'numpy' has no attribute 'object'. np.object was a deprecated alias for the builtin object. To avoid this error in existing code, use object by itself. Doing this will not modify any behavior and is safe. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'object_'?

Please note that I tried downgrading the pyscenic to 0.12.0 but it gets stuck on this same command: pyscenic grn "${f_loom_path_scenic}" "${f_tfs}" -o adj.csv --num_workers 16

2024-03-29 00:48:52,260 - pyscenic.cli.pyscenic - INFO - Loading expression matrix.

2024-03-29 00:49:55,833 - pyscenic.cli.pyscenic - INFO - Inferring regulatory networks. preparing dask client parsing input creating dask graph 16 partitions computing dask graph /ahg/regevdata/projects/ICA_Lung/Nishant/conda/envs/pyscenic3pt8/lib/python3.8/site-packages/distributed/client.py:3108: UserWarning: Sending large graph of size 2.80 GiB. This may cause some slowdown. Consider scattering data ahead of time and using futures. warnings.warn(

Tripfantasy commented 7 months ago

Facing the same issue:

Hello, have you tried looking at /micromamba/envs/pyscenic/lib/python3.10/site-packages/numpy/__init__.py", line 324 ? It has a dictionary of aliases and datatypes. See if it matches what I have in the potential solution in the third point of my post.

I am interested to see if just changing the value like I had fixes it for others as well.

iamakhilverma commented 7 months ago

Facing the same issue:

Hello, have you tried looking at /micromamba/envs/pyscenic/lib/python3.10/site-packages/numpy/__init__.py", line 324 ? It has a dictionary of aliases and datatypes. See if it matches what I have in the potential solution in the third point of my post.

I am interested to see if just changing the value like I had fixes it for others as well.

I just updated my _type_info dictionary, and it doesn't throw that error anymore. I'll let you know if it runs successfully.

Update 1: It didn't work for me, it kept giving me some other issues with the package. Trying with the installation of pySCENIC from git now.

Update 2: Installation from git repo worked successfully!

ghuls commented 7 months ago

Installing pySCENIC from git should fix this: https://github.com/aertslab/pySCENIC/commit/eaf23eb1fdcaae79b273de56b374b71aa8afde5a

dmalzl commented 5 months ago

I am facing the very same issue. Judging by the error message this can be easily fixed by just changing to object as written below:

AttributeError: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe. 
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

I understand that this may not occur when installing from git. However, the proposed mode of installation in the docs is pip so changing to object would also up the usability of the package

Edit: Just saw that this has already been done. So it is really an issue with the version fetched from PyPI