Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] adding an option to read file from s3 #1322

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion anndata/_core/file_backing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions anndata/tests/test_readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading