From 555c15c8a170944b762ba7ce1d8c0b41f4e4dfbe Mon Sep 17 00:00:00 2001 From: Philipp A Date: Fri, 25 May 2018 10:31:47 +0200 Subject: [PATCH] Made it work and test on 3.5 again --- .travis.yml | 2 +- anndata/base.py | 8 ++++---- anndata/h5py/h5sparse.py | 2 +- anndata/readwrite/write.py | 4 ++-- anndata/tests/readwrite.py | 4 ++++ anndata/utils.py | 4 ++-- requires_tests.txt | 2 +- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 518e094a9..02cb180d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: - #- "3.5" # loompy needs python 3.6 + - "3.5" - "3.6" install: - "pip install -r requires.txt" diff --git a/anndata/base.py b/anndata/base.py index 9377a7b0e..8b9cd9ca6 100644 --- a/anndata/base.py +++ b/anndata/base.py @@ -284,7 +284,7 @@ def __repr__(self): if self._filename is None: return 'Backing file manager: no file is set.' else: - return f'Backing file manager of file {self._filename}.' + return 'Backing file manager of file {}.'.format(self._filename) def __getitem__(self, key): return self._file[key] @@ -523,9 +523,9 @@ def __init__(self, n_dims): class AnnData(IndexMixin, metaclass=utils.DeprecationMixinMeta): - __doc__ = dedent(f"""An annotated data matrix. + __doc__ = dedent("""An annotated data matrix. - {indent(_MAIN_NARRATIVE, 4*' ')} + {} Parameters ---------- @@ -583,7 +583,7 @@ class AnnData(IndexMixin, metaclass=utils.DeprecationMixinMeta): .. _statsmodels: http://www.statsmodels.org/stable/index.html .. _scikit-learn: http://scikit-learn.org/ - """) + """).format(indent(_MAIN_NARRATIVE, 4*' ')) _BACKED_ATTRS = ['X', 'raw.X'] diff --git a/anndata/h5py/h5sparse.py b/anndata/h5py/h5sparse.py index 350827a85..48e0f2ef0 100644 --- a/anndata/h5py/h5sparse.py +++ b/anndata/h5py/h5sparse.py @@ -98,7 +98,7 @@ def __init__( libver: Optional[str] = None, userblock_size: Optional[int] = None, swmr: bool = False, - **kwds, + **kwds # Python 3.5 can’t handle trailing commas here ): self.h5f = h5py.File( name, diff --git a/anndata/readwrite/write.py b/anndata/readwrite/write.py index ae4f7ad6b..768b27a2b 100644 --- a/anndata/readwrite/write.py +++ b/anndata/readwrite/write.py @@ -45,7 +45,7 @@ def write_csvs(dirname: Union[Path, str], adata: AnnData, skip_data: bool = True filename = dirname if key not in {'X', 'var', 'obs', 'obsm', 'varm'}: filename = dir_uns - filename /= f'{key}.csv' + filename /= '{}.csv'.format(key) df = value if not isinstance(value, pd.DataFrame): value = np.array(value) @@ -54,7 +54,7 @@ def write_csvs(dirname: Union[Path, str], adata: AnnData, skip_data: bool = True try: df = pd.DataFrame(value) except Exception as e: - warnings.warn(f'Omitting to write {key!r}.', type(e)) + warnings.warn('Omitting to write {!r}.'.format(key), type(e)) continue df.to_csv( filename, sep=sep, diff --git a/anndata/tests/readwrite.py b/anndata/tests/readwrite.py index 27f9895db..c98eef00e 100644 --- a/anndata/tests/readwrite.py +++ b/anndata/tests/readwrite.py @@ -1,13 +1,16 @@ +from importlib.util import find_spec from pathlib import Path import numpy as np import pandas as pd +import pytest from scipy.sparse import csr_matrix import anndata as ad HERE = Path(__file__).parent + # ------------------------------------------------------------------------------- # Some test data # ------------------------------------------------------------------------------- @@ -61,6 +64,7 @@ def test_readwrite_dynamic(): assert adata.obs['oanno1'].cat.categories.tolist() == ['cat1', 'cat2'] +@pytest.mark.skipif(not find_spec('loompy'), reason='Loompy is not installed (expected on Python 3.5)') def test_readwrite_loom(): for i, typ in enumerate([np.array, csr_matrix]): X = typ(X_list) diff --git a/anndata/utils.py b/anndata/utils.py index c90800aa2..da8dc2475 100644 --- a/anndata/utils.py +++ b/anndata/utils.py @@ -92,8 +92,8 @@ def decorator(func): def new_func(*args, **kwargs): warnings.simplefilter('always', DeprecationWarning) # turn off filter warnings.warn( - f'Use {new_name} instead of {func.__name__}, ' - f'{func.__name__} will be removed in the future.', + 'Use {0} instead of {1}, {1} will be removed in the future.' + .format(new_name, func.__name__), category=DeprecationWarning, stacklevel=2, ) diff --git a/requires_tests.txt b/requires_tests.txt index 48f4aeb6c..2ffae3d1b 100644 --- a/requires_tests.txt +++ b/requires_tests.txt @@ -1 +1 @@ -loompy>=2.0 +loompy>=2.0; python_version>='3.6'