From 4538dddee07bb540661e2938aa4a2bfbf34d341d Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 8 Jun 2019 12:35:56 +0200 Subject: [PATCH 1/2] Simplified gitignore --- .gitignore | 121 +++++++---------------------------------------------- 1 file changed, 14 insertions(+), 107 deletions(-) diff --git a/.gitignore b/.gitignore index 99ba5923a..b49f525e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,116 +1,23 @@ -*~ - -# tests -*.pytest_cache/* - -# anndata -docs/_build -docs/anndata.* - -# Mac +# Temp files .DS_Store +*~ -# Byte-compiled / optimized / DLL files +# Compiled files __pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so # Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# dotenv -.env - -# virtualenv -.venv -venv/ -ENV/ - -# Spyder project settings -.spyderproject -.spyproject +/build/ +/dist/ +/*.egg-info/ -# Rope project settings -.ropeproject +# Tests and coverage +/.pytest_cache/ +/.cache/ -# PyCharm project settings -.idea/ +# docs +/docs/anndata.* +/docs/_build/ -# mkdocs documentation -/site +# IDEs +/.idea/ -# mypy -.mypy_cache/ From e9ccfc33fa4152ad4e137dea4e5700386c0e4da0 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 8 Jun 2019 12:38:28 +0200 Subject: [PATCH 2/2] Remove os --- anndata/core/anndata.py | 3 +- anndata/tests/test_h5py.py | 64 +++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/anndata/core/anndata.py b/anndata/core/anndata.py index 36db07508..31a658b87 100644 --- a/anndata/core/anndata.py +++ b/anndata/core/anndata.py @@ -1,6 +1,5 @@ """Main class and helper functions. """ -import os from enum import Enum from collections import OrderedDict from collections.abc import MutableMapping @@ -1152,7 +1151,7 @@ def filename(self, filename: Optional[PathLike]): # write the content of self to the old file # and close the file self.write() - os.rename(self.filename, filename) + self.filename.rename(filename) else: # do nothing return diff --git a/anndata/tests/test_h5py.py b/anndata/tests/test_h5py.py index 703c88bb8..49d514cd1 100644 --- a/anndata/tests/test_h5py.py +++ b/anndata/tests/test_h5py.py @@ -1,22 +1,20 @@ # Had to rename the test module to h5py_ so that it wouldn't conflict with the # h5py import upon testing. -import os -from tempfile import mkstemp - import numpy as np import scipy.sparse as ss from anndata import h5py -def test_create_and_read_dataset(): - h5_path = mkstemp(suffix=".h5")[1] - sparse_matrix = ss.csr_matrix([[0, 1, 0], - [0, 0, 1], - [0, 0, 0], - [1, 1, 0]], - dtype=np.float64) +def test_create_and_read_dataset(tmp_path): + h5_path = tmp_path / 'test.h5' + sparse_matrix = ss.csr_matrix([ + [0, 1, 0], + [0, 0, 1], + [0, 0, 0], + [1, 1, 0], + ], dtype=np.float64) with h5py.File(h5_path) as h5f: h5f.create_dataset('sparse/matrix', data=sparse_matrix) with h5py.File(h5_path) as h5f: @@ -27,17 +25,16 @@ def test_create_and_read_dataset(): assert (h5f['sparse']['matrix'][:-2] != sparse_matrix[:-2]).size == 0 assert (h5f['sparse']['matrix'].value != sparse_matrix).size == 0 - os.remove(h5_path) - -def test_create_dataset_from_dataset(): - from_h5_path = mkstemp(suffix=".h5")[1] - to_h5_path = mkstemp(suffix=".h5")[1] - sparse_matrix = ss.csr_matrix([[0, 1, 0], - [0, 0, 1], - [0, 0, 0], - [1, 1, 0]], - dtype=np.float64) +def test_create_dataset_from_dataset(tmp_path): + from_h5_path = tmp_path / 'from.h5' + to_h5_path = tmp_path / 'to.h5' + sparse_matrix = ss.csr_matrix([ + [0, 1, 0], + [0, 0, 1], + [0, 0, 0], + [1, 1, 0], + ], dtype=np.float64) with h5py.File(from_h5_path) as from_h5f: from_dset = from_h5f.create_dataset('sparse/matrix', data=sparse_matrix) @@ -45,25 +42,22 @@ def test_create_dataset_from_dataset(): to_h5f.create_dataset('sparse/matrix', data=from_dset) assert (to_h5f['sparse/matrix'].value != sparse_matrix).size == 0 - os.remove(from_h5_path) - os.remove(to_h5_path) - -def test_dataset_append(): - h5_path = mkstemp(suffix=".h5")[1] - sparse_matrix = ss.csr_matrix([[0, 1, 0], - [0, 0, 1], - [0, 0, 0], - [1, 1, 0]], - dtype=np.float64) - to_append = ss.csr_matrix([[0, 1, 1], - [1, 0, 0]], - dtype=np.float64) +def test_dataset_append(tmp_path): + h5_path = tmp_path / 'test.h5' + sparse_matrix = ss.csr_matrix([ + [0, 1, 0], + [0, 0, 1], + [0, 0, 0], + [1, 1, 0], + ], dtype=np.float64) + to_append = ss.csr_matrix([ + [0, 1, 1], + [1, 0, 0], + ], dtype=np.float64) appended_matrix = ss.vstack((sparse_matrix, to_append)) with h5py.File(h5_path) as h5f: h5f.create_dataset('matrix', data=sparse_matrix, chunks=(100000,)) h5f['matrix'].append(to_append) assert (h5f['matrix'].value != appended_matrix).size == 0 - - os.remove(h5_path)