From faab93f37a2943d11c56bcb0bf199b0a1b241d8f Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Fri, 19 Jan 2024 14:53:29 -0500 Subject: [PATCH 1/3] adding a simple addition to open remfile --- anndata/_core/file_backing.py | 5 ++++- pyproject.toml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/anndata/_core/file_backing.py b/anndata/_core/file_backing.py index c50a2ea8d..1b4833af5 100644 --- a/anndata/_core/file_backing.py +++ b/anndata/_core/file_backing.py @@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Literal import h5py +import remfile from ..compat import AwkArray, DaskArray, ZarrArray, ZarrGroup from .sparse_dataset import BaseCompressedSparseDataset @@ -65,7 +66,9 @@ def filename(self) -> Path: @filename.setter def filename(self, filename: PathLike | None): - self._filename = None if filename is None else Path(filename) + self._filename = None if filename is None \ + else filename if isinstance(filename, remfile.RemFile.RemFile) \ + else Path(filename) def open( self, diff --git a/pyproject.toml b/pyproject.toml index f9f0b0d39..73dc646fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ dependencies = [ "numpy>=1.16.5", # required by pandas 1.x "scipy>1.4", "h5py>=3", + "remfile", "exceptiongroup; python_version<'3.11'", "natsort", "packaging>=20", From 48b436d172d8a12ba8346976f632a7a1665f2a48 Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Fri, 19 Jan 2024 16:19:56 -0500 Subject: [PATCH 2/3] adding a simple test --- anndata/tests/test_readwrite.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/anndata/tests/test_readwrite.py b/anndata/tests/test_readwrite.py index 4b59791fd..a1f2cdea2 100644 --- a/anndata/tests/test_readwrite.py +++ b/anndata/tests/test_readwrite.py @@ -797,3 +797,15 @@ def test_io_dtype(tmp_path, diskfmt, dtype): curr = read(pth) assert curr.X.dtype == dtype + + +needs_remfile = pytest.mark.skipif(not find_spec("remfile"), reason="remfile is not installed") + +@needs_remfile +def test_read_s3_remfile(): + import remfile + # TODO: change to a different datafile? + url_had = "https://allen-brain-cell-atlas.s3.us-west-2.amazonaws.com/expression_matrices/WMB-10Xv2/20230630/WMB-10Xv2-TH-log2.h5ad" + file_had = remfile.File(url_had) + data = ad.read_h5ad(file_had, backed='r') + assert data.X.shape == (131212, 32285) From 18ddcd0970bd971a5e52486cbc89b7456f3925d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:32:04 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- anndata/_core/file_backing.py | 8 ++++++-- anndata/tests/test_readwrite.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/anndata/_core/file_backing.py b/anndata/_core/file_backing.py index 1b4833af5..39a2e9709 100644 --- a/anndata/_core/file_backing.py +++ b/anndata/_core/file_backing.py @@ -66,9 +66,13 @@ def filename(self) -> Path: @filename.setter def filename(self, filename: PathLike | None): - self._filename = None if filename is None \ - else filename if isinstance(filename, remfile.RemFile.RemFile) \ + self._filename = ( + None + if filename is None + else filename + if isinstance(filename, remfile.RemFile.RemFile) else Path(filename) + ) def open( self, diff --git a/anndata/tests/test_readwrite.py b/anndata/tests/test_readwrite.py index a1f2cdea2..f1e4c83b6 100644 --- a/anndata/tests/test_readwrite.py +++ b/anndata/tests/test_readwrite.py @@ -799,13 +799,17 @@ def test_io_dtype(tmp_path, diskfmt, dtype): assert curr.X.dtype == dtype -needs_remfile = pytest.mark.skipif(not find_spec("remfile"), reason="remfile is not installed") +needs_remfile = pytest.mark.skipif( + not find_spec("remfile"), reason="remfile is not installed" +) + @needs_remfile def test_read_s3_remfile(): import remfile + # TODO: change to a different datafile? url_had = "https://allen-brain-cell-atlas.s3.us-west-2.amazonaws.com/expression_matrices/WMB-10Xv2/20230630/WMB-10Xv2-TH-log2.h5ad" file_had = remfile.File(url_had) - data = ad.read_h5ad(file_had, backed='r') + data = ad.read_h5ad(file_had, backed="r") assert data.X.shape == (131212, 32285)