diff --git a/anndata/_core/file_backing.py b/anndata/_core/file_backing.py index c50a2ea8d..39a2e9709 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,13 @@ 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/anndata/tests/test_readwrite.py b/anndata/tests/test_readwrite.py index 4b59791fd..f1e4c83b6 100644 --- a/anndata/tests/test_readwrite.py +++ b/anndata/tests/test_readwrite.py @@ -797,3 +797,19 @@ 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) 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",