Skip to content

Commit

Permalink
Merge pull request #71 from scverse/mudata-0.3.0rc1
Browse files Browse the repository at this point in the history
v0.3.0rc1 fixes and improvements
  • Loading branch information
gtca authored Aug 1, 2024
2 parents 20f74a8 + 5b33420 commit 7e97559
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
25 changes: 24 additions & 1 deletion docs/source/io/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,31 @@ MuData objects can be read and cached from remote locations including via HTTP(S
A caching layer can be added in the following way:
::
fname_cached = "filecache::" + fname
with fsspec.open(fname_cached, filecache={'cache_storage': '/tmp/'}):
with fsspec.open(fname_cached, filecache={'cache_storage': '/tmp/'}) as f:
mdata = mudata.read_h5mu(f)


For more `fsspec` usage examples see [its documentation](https://filesystem-spec.readthedocs.io/).

S3
^^

MuData objects in the ``.h5mu`` format stored in an S3 bucket can be read with ``fsspec`` as well:
::
storage_options = {
'endpoint_url': 'localhost:9000',
'key': 'AWS_ACCESS_KEY_ID',
'secret': 'AWS_SECRET_ACCESS_KEY',
}

with fsspec.open('s3://bucket/dataset.h5mu', **storage_options) as f:
mudata.read_h5mu(f)


MuData objects stored in the ``.zarr`` format in an S3 bucket can be read from a *mapping*:
::
import s3fs

s3 = s3fs.S3FileSystem(**storage_options)
store = s3.get_mapper('s3://bucket/dataset.zarr')
mdata = mudata.read_zarr(store)
5 changes: 4 additions & 1 deletion src/mudata/_core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,13 @@ def _validate_h5mu(filename: PathLike) -> (str, Callable | None):
# with fsspec.open("s3://bucket/file.h5mu") as f:
# mdata = read_h5mu(f)
# or
# mdata = read_h5mu(fsspec.open("s3://bucket/file.h5mu")
# mdata = read_h5mu(fsspec.open("s3://bucket/file.h5mu"))
if (
filename.__class__.__name__ == "BufferedReader"
or filename.__class__.__name__ == "OpenFile"
or filename.__class__.__name__ == "HTTPFile"
or filename.__class__.__name__ == "HTTPStreamFile"
or filename.__class__.__name__ == "S3File"
):
try:
from fsspec.core import OpenFile
Expand Down
2 changes: 1 addition & 1 deletion src/mudata/_core/mudata.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def _update_attr(
if OPTIONS["pull_on_update"] is None:
warnings.warn(
"From 0.4 .update() will not pull obs/var columns from individual modalities by default anymore. "
"Set mudate.set_options(pull_on_update=False) to adopt the new behaviour, which will become the default. "
"Set mudata.set_options(pull_on_update=False) to adopt the new behaviour, which will become the default. "
"Use new pull_obs/pull_var and push_obs/push_var methods for more flexibility.",
FutureWarning,
stacklevel=2,
Expand Down

0 comments on commit 7e97559

Please sign in to comment.