tanaylab / metacells

Metacells - Single-cell RNA Sequencing Analysis
MIT License
86 stars 8 forks source link

scipy.sparse.compressed error #23

Closed rargelaguet closed 1 year ago

rargelaguet commented 2 years ago

Hello, I've run the basic metacells tutorial but I encounter the following error when running mc.pl.divide_and_conquer_pipeline:

AttributeError: scipy.sparse.compressed is deprecated and has no attribute _cs_matrix. Try looking in scipy.sparse instead.

which occurs when calling this code:

File ~/opt/anaconda3/envs/main/envs/metacells/lib/python3.9/site-packages/metacells/utilities/typing.py:414, in maybe_compressed_matrix(shaped)
    410 def maybe_compressed_matrix(shaped: Any) -> Optional[CompressedMatrix]:
    411     """
    412     Return ``shaped`` as a :py:const:`CompressedMatrix`, if it is one.
    413     """
--> 414     if isinstance(shaped, sp.compressed._cs_matrix):  # pylint: disable=protected-access
    415         return shaped
    416     return None

Is this a versioning problem on my side? Here are my imports:

-----
anndata             0.7.8
matplotlib          3.5.1
metacells           0.7.0
numpy               1.22.2
pandas              1.4.1
scanpy              1.8.2
scipy               1.8.0
seaborn             0.11.2
session_info        1.0.0
-----
Click to view modules imported as dependencies
-----
IPython             8.0.1
jupyter_client      7.1.2
jupyter_core        4.9.2
notebook            6.4.8
-----
Python 3.9.10 | packaged by conda-forge | (main, Feb  1 2022, 21:28:27) [Clang 11.1.0 ]
macOS-11.6-x86_64-i386-64bit
-----

Here is also my conda environment (conda env create -f metacells_env.yml), if you want to try reproduce it.

name: metacells
channels:
  - conda-forge
  - bioconda
dependencies:
  - scanpy=1.8.2
  - h5py=2.10.0
  - loompy=3.0.6
  - jupyter
  - mamba
  - louvain
  - genomepy
  - scipy
  - numpy
  - seaborn
  - pandas
  - pyyaml
  - python-igraph
  - umap-learn
  - pip
  - pip:
    - dfply
    - metacells

Thanks, Ricard

orenbenkiki commented 2 years ago

Hmmm. Seems like a new thing in scipy 1.8.0, not an issue w/ scipy versions 1.7.* which I have been using so far.

The fix is to change isinstance(shaped, sp.compressed._cs_matrix) to isinstance(shaped, (sp.csr_matrix, sp.csc_matrix)). This appears in two places in the code, if you want to patch it manually you can do this as a stopgag measure until I publish the next release.

Thanks for reporting this!

orenbenkiki commented 1 year ago

This is part of the about-to-be-released version 0.9. Note that version 0.9 is different from version 0.8 (see the project README). It is in final testing phases, currently you can only install it from the head version in github.

orenbenkiki commented 1 year ago

Version 0.9 is now published so closing this as done.