scverse / squidpy

Spatial Single Cell Analysis in Python
https://squidpy.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
439 stars 79 forks source link

pandas version #382

Closed igordot closed 3 years ago

igordot commented 3 years ago

Description

After updating pandas to 1.3.0, I started getting errors with gr.ligrec. Reinstalling 1.2.5 seemed to have solved this.

Traceback

```pytb --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in ----> 1 res = sq.gr.ligrec( 2 adata, 3 n_perms=1000, 4 cluster_key="cluster", 5 copy=True, /path/python3.9/site-packages/squidpy/gr/_ligrec.py in ligrec(adata, cluster_key, interactions, complex_policy, threshold, corr_method, corr_axis, use_raw, copy, key_added, **kwargs) 647 """ # noqa: D400 648 return ( # type: ignore[no-any-return] --> 649 PermutationTest(adata, use_raw=use_raw) 650 .prepare(interactions, complex_policy=complex_policy, **kwargs) 651 .test( /path/python3.9/site-packages/squidpy/gr/_ligrec.py in prepare(self, interactions, complex_policy, interactions_params, transmitter_params, receiver_params, **_) 593 594 start = logg.info("Fetching interactions from `omnipath`") --> 595 interactions = import_intercell_network( 596 interactions_params=interactions_params, 597 transmitter_params=transmitter_params, /path/python3.9/site-packages/omnipath/_core/requests/interactions/_utils.py in import_intercell_network(include, interactions_params, transmitter_params, receiver_params) 98 receiver_params.setdefault("scope", "generic") 99 --> 100 interactions = AllInteractions.get(include=include, **interactions_params) 101 if interactions.empty: 102 raise ValueError(_ERROR_EMPTY_FMT.format(obj="interactions")) /path/python3.9/site-packages/omnipath/_core/requests/_utils.py in wrapper(wrapped, _instance, args, kwargs) 102 @wrapt.decorator(adapter=wrapt.adapter_factory(argspec_factory)) 103 def wrapper(wrapped, _instance, args, kwargs): --> 104 return wrapped(*args, **kwargs) 105 106 if hasattr(clazz, "get") and not hasattr(clazz.get, "__wrapped__"): /path/python3.9/site-packages/omnipath/_core/requests/interactions/_interactions.py in get(cls, include, exclude, **kwargs) 375 %(get.returns)s 376 """ --> 377 return cls(include, exclude=exclude)._get(**kwargs) 378 379 /path/python3.9/site-packages/omnipath/_core/requests/_request.py in _get(self, **kwargs) 105 kwargs = self._finalize_params(kwargs) 106 --> 107 res = self._downloader.maybe_download( 108 self._query_type.endpoint, params=kwargs, callback=callback, is_final=False 109 ) /path/python3.9/site-packages/omnipath/_core/downloader/_downloader.py in maybe_download(self, url, callback, params, cache, is_final, **_) 124 if key in self._options.cache: 125 logging.debug(f"Found data in cache `{self._options.cache}[{key!r}]`") --> 126 res = self._options.cache[key] 127 else: 128 res = callback(self._download(req)) /path/python3.9/site-packages/omnipath/_core/cache/_cache.py in __getitem__(self, key) 86 87 with open(self._cache_dir / key, "rb") as fin: ---> 88 return pickle.load(fin) 89 90 def __len__(self) -> int: /path/python3.9/site-packages/pandas/_libs/internals.pyx in pandas._libs.internals.BlockManager.__cinit__() TypeError: __cinit__() takes at least 2 positional arguments (0 given) ```

Version

scanpy==1.8.1 anndata==0.7.6 umap==0.5.1 numpy==1.20.3 scipy==1.6.3 pandas==1.3.0 scikit-learn==0.22 statsmodels==0.12.2 python-igraph==0.9.4 pynndescent==0.5.2

ivirshup commented 3 years ago

Looks related to a pandas 1.3 bug I noticed while reporting bugs that broke scanpy 1.8: https://github.com/pandas-dev/pandas/issues/42345

michalk8 commented 3 years ago

Seems to be related to https://github.com/pandas-dev/pandas/issues/42345. I can see that base on the trace, omnipath tries to load the data from cache, clearing the cache should fix it:

import omnpath as op
op.clear_cache()
igordot commented 3 years ago

Thank you for looking into this so quickly!

import omnpath as op
op.clear_cache()

That does seem to solve the error (there was a typo in omnipath in the original post), but it introduces a few new warnings:

/path/python3.9/site-packages/omnipath/_core/downloader/_downloader.py:128: DtypeWarning: Columns (8) have mixed types.Specify dtype option on import or set low_memory=False.
  res = callback(self._download(req))
/path/python3.9/site-packages/omnipath/_core/requests/_utils.py:155: FutureWarning: The default value of regex will change from True to False in a future version.
  _split_unique_join(data.str.replace(r"[-\w]*:?(\d+)", r"\1")), func=func
/path/python3.9/site-packages/squidpy/gr/_ligrec.py:376: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider using pd.concat instead.  To get a de-fragmented frame, use `newframe = frame.copy()`
  self._filtered_data["clusters"] = self._adata.obs[cluster_key].astype("string").astype("category").values
/path/python3.9/site-packages/pandas/core/arrays/categorical.py:2630: FutureWarning: The `inplace` parameter in pandas.Categorical.rename_categories is deprecated and will be removed in a future version. Removing unused categories will always return a new Categorical object.
  res = method(*args, **kwargs)
michalk8 commented 3 years ago

Sorry for the typo. Re warnings: these have been fixed in https://github.com/saezlab/omnipath/commit/60af5bff7d5e7bcb69c81dd640d5a605aed61c2a, but I haven't made a new version on PyPI (didn't think this would warrant it). They should go away if you install the latest version from GitHub as:

pip install git+https://github.com/saezlab/omnipath 
igordot commented 3 years ago

No problem. It's definitely a very minor issue. I just wanted to mention it since I already initiated this thread.

michalk8 commented 3 years ago

This issue seems to be solved then, closing this.