diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index d71eab3c..be00719e 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -34,12 +34,14 @@ jobs: - name: Install tools run: | - python -m pip install --upgrade "pip<=21.0" - pip install --use-deprecated=legacy-resolver -U wheel setuptools - pip install --use-deprecated=legacy-resolver -U black flake8 + python -m pip install --upgrade pip + pip install -U wheel setuptools + pip install -U black flake8 + - name: Lint with Black run: | black . --check --diff + - name: Lint with flake8 run: | flake8 scprep @@ -101,6 +103,13 @@ jobs: restore-keys: | ${{ runner.os }}-renv-${{ steps.setup-r.outputs.installed-r-version }}- + - name: Install package & dependencies + run: | + python -m pip install --upgrade pip + pip install --upgrade wheel setuptools + pip install --upgrade .[test] + python -c "import scprep" + - name: Install R packages run: | if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") @@ -109,13 +118,6 @@ jobs: renv::install("bioc::slingshot") shell: Rscript {0} - - name: Install package & dependencies - run: | - python -m pip install --upgrade "pip<=21.0" - pip install --use-deprecated=legacy-resolver -U wheel setuptools - pip install --use-deprecated=legacy-resolver -U .[test,r] - python -c "import scprep" - - name: Run tests run: nose2 -vvv diff --git a/scprep/__init__.py b/scprep/__init__.py index 1156e639..f5674ba3 100644 --- a/scprep/__init__.py +++ b/scprep/__init__.py @@ -15,18 +15,6 @@ import scprep.reduce import scprep.run -import pandas as _pd -import packaging.version as _packaging_version +from . import _patch -if _packaging_version.parse(_pd.__version__) < _packaging_version.parse("2.0"): - - def _fill_value(self): - # Used in reindex_indexer - try: - return self.values.dtype.fill_value - except AttributeError: - return self.values.dtype.na_value - - from pandas.core.internals.blocks import ExtensionBlock as _ExtensionBlock - - setattr(_ExtensionBlock, "fill_value", property(_fill_value)) +_patch.patch_fill_value() diff --git a/scprep/_patch.py b/scprep/_patch.py new file mode 100644 index 00000000..da5b136b --- /dev/null +++ b/scprep/_patch.py @@ -0,0 +1,17 @@ +import packaging.version +import pandas as pd + + +def patch_fill_value(): + if packaging.version.parse(pd.__version__) < packaging.version.parse("2.0"): + + def _fill_value(self): + # Used in reindex_indexer + try: + return self.values.dtype.fill_value + except AttributeError: + return self.values.dtype.na_value + + from pandas.core.internals.blocks import ExtensionBlock + + setattr(ExtensionBlock, "fill_value", property(_fill_value)) diff --git a/scprep/plot/jitter.py b/scprep/plot/jitter.py index c0f75927..49c9d177 100644 --- a/scprep/plot/jitter.py +++ b/scprep/plot/jitter.py @@ -195,12 +195,12 @@ def jitter( # Plotting means if plot_means: + plot_x_means = [ + i for i in range(len(params.x_labels)) if np.any(params.x_coords == i) + ] ax.scatter( - np.arange(len(params.x_labels)), - [ - np.nanmean(params.y[params.x_coords == i]) - for i in range(len(params.x_labels)) - ], + plot_x_means, + [np.nanmean(params.y[params.x_coords == i]) for i in plot_x_means], c=means_c, edgecolors="black", lw=1.5, diff --git a/scprep/plot/utils.py b/scprep/plot/utils.py index d54bc0af..4ab07191 100644 --- a/scprep/plot/utils.py +++ b/scprep/plot/utils.py @@ -14,7 +14,10 @@ def _with_default(param, default): def _mpl_is_gui_backend(): - backend = mpl.get_backend() + try: + backend = mpl.get_backend() + except Exception: + return False if backend in ["module://ipykernel.pylab.backend_inline", "agg"]: return False else: diff --git a/scprep/version.py b/scprep/version.py index deae1c8e..d6e6e024 100644 --- a/scprep/version.py +++ b/scprep/version.py @@ -1,4 +1,4 @@ # author: Scott Gigante # (C) 2018 Krishnaswamy Lab GPLv2 -__version__ = "1.0.12" +__version__ = "1.0.13" diff --git a/setup.py b/setup.py index 62b07929..fd09f748 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,7 @@ "scikit-learn>=0.19.1", "decorator>=4.3.0", "pandas>=0.25", + "packaging", ] optional_requires = [ @@ -41,7 +42,7 @@ doc_requires += ["autodocsumm!=0.2.0"] else: test_requires += ["matplotlib>=3.0", "rpy2>=3.0", "black"] - optional_requires += ["anndata2ri"] + optional_requires += ["anndata2ri>=1.0.6"] doc_requires += ["autodocsumm"] version_py = os.path.join(os.path.dirname(__file__), "scprep", "version.py") diff --git a/test.png b/test.png deleted file mode 100644 index 01c74e2d..00000000 Binary files a/test.png and /dev/null differ diff --git a/test/_test_lazyload.py b/test/_test_lazyload.py index da566078..5a24993b 100644 --- a/test/_test_lazyload.py +++ b/test/_test_lazyload.py @@ -14,11 +14,11 @@ def test_lazyload(): for module in scprep._lazyload._importspec.keys(): if module == "anndata2ri" and sys.version_info[:2] < (3, 6): continue - if module in preloaded_modules: - assert getattr(scprep._lazyload, module).__class__ is type(scprep) + assert module not in scprep_loaded, module + if module in postloaded_modules: + assert getattr(scprep._lazyload, module).__class__ is type(scprep), module else: assert ( getattr(scprep._lazyload, module).__class__ is scprep._lazyload.AliasModule - ) - assert module not in scprep_loaded, module + ), module diff --git a/test/test_hdf5.py b/test/test_hdf5.py index 882ded34..cee47972 100644 --- a/test/test_hdf5.py +++ b/test/test_hdf5.py @@ -68,7 +68,7 @@ def test_get_node_invalid(): def test_get_values_invalid(): utils.assert_raises_message( TypeError, - "Expected h5py.Dataset or tables.CArray. " "Got ", + "Expected h5py.Dataset or tables.CArray. Got ", scprep.io.hdf5.get_values, "invalid", ) diff --git a/test/test_lazyload.py b/test/test_lazyload.py index 7e23bc41..e4cfab81 100644 --- a/test/test_lazyload.py +++ b/test/test_lazyload.py @@ -1,4 +1,5 @@ import subprocess +import mock import os import scprep import sys @@ -23,18 +24,16 @@ def test_lazyload(): def test_builtins(): - for module in scprep._lazyload._importspec.keys(): - if module == "anndata2ri" and sys.version_info[:2] < (3, 6): + for module_name in scprep._lazyload._importspec.keys(): + if module_name == "anndata2ri" and sys.version_info[:2] < (3, 6): continue - try: - del sys.modules[module] - except KeyError: - pass - assert ( - getattr(scprep._lazyload, module).__class__ is scprep._lazyload.AliasModule - ) - try: - getattr(scprep._lazyload, module).__version__ - except AttributeError: - pass - assert getattr(scprep._lazyload, module).__class__ is type(scprep) + with mock.patch.dict(sys.modules): + if module_name in sys.modules: + del sys.modules[module_name] + module = getattr(scprep._lazyload, module_name) + assert module.__class__ is scprep._lazyload.AliasModule, ( + module_name, + module, + ) + module.__package__ + assert module.__class__ is type(scprep), (module_name, module)