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

implement lindi.File, drop-in replacement for h5py.File that supports .lindi.json files based on extension (4) #60

Merged
merged 15 commits into from
May 9, 2024

Conversation

magland
Copy link
Collaborator

@magland magland commented Apr 25, 2024

No description provided.

@magland magland changed the base branch from main to write-json April 25, 2024 20:41
@codecov-commenter
Copy link

codecov-commenter commented Apr 26, 2024

Codecov Report

Attention: Patch coverage is 78.94737% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 81.47%. Comparing base (3b08289) to head (089b6ee).
Report is 1 commits behind head on write-json.

Files Patch % Lines
lindi/File/File.py 88.88% 2 Missing ⚠️
lindi/LindiH5ZarrStore/LindiH5ZarrStore.py 50.00% 2 Missing ⚠️
lindi/LindiH5pyFile/LindiH5pyFile.py 71.42% 2 Missing ⚠️
lindi/LindiStagingStore/StagingArea.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##           write-json      #60      +/-   ##
==============================================
+ Coverage       79.95%   81.47%   +1.52%     
==============================================
  Files              29       30       +1     
  Lines            2155     2208      +53     
==============================================
+ Hits             1723     1799      +76     
+ Misses            432      409      -23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@magland
Copy link
Collaborator Author

magland commented May 9, 2024

Here we make a lindi.File that can be a drop-in replacement for h5py.File, where it smartly decides whether to use h5py or lindi based on the file extension of the file name.

This PR corrects a few small issues/mistakes from previous PRs.

@@ -52,6 +52,9 @@ def from_lindi_file(url_or_path: str, *, mode: LindiFileMode = "r", staging_area

For a description of parameters, see from_reference_file_system().
"""
if local_file_path is None:
if not url_or_path.startswith("http://") and not url_or_path.startswith("https://"):
local_file_path = url_or_path
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the local file path (the one that can get edited) to be equal to the url_or_path in the case that it is not provided and is not a url

@@ -166,7 +169,7 @@ def from_reference_file_system(rfs: Union[dict, str, None], *, mode: LindiFileMo
store = LindiReferenceFileSystemStore(rfs, local_cache=local_cache)
if staging_area:
store = LindiStagingStore(base_store=store, staging_area=staging_area)
return LindiH5pyFile.from_zarr_store(store, mode=mode, local_file_path=local_file_path)
return LindiH5pyFile.from_zarr_store(store, mode=mode, local_file_path=local_file_path, local_cache=local_cache)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was accidentally omitted.

Comment on lines +25 to +45
def create(*, base_dir: Union[str, None] = None, dir: Union[str, None] = None) -> 'StagingArea':
"""
Create a new staging area.
Create a new staging area. Provide either `base_dir` or `dir`, but not
both.

Parameters
----------
base_dir : str
The base directory where the staging area will be created. The
staging directory will be a subdirectory of this directory.
base_dir : str or None
If provided, the base directory where the staging area will be
created. The staging directory will be a subdirectory of this
directory.
dir : str or None
If provided, the exact directory where the staging area will be
created. It is okay if this directory already exists.
"""
dir = os.path.join(base_dir, _create_random_id())
if base_dir is not None and dir is not None:
raise ValueError("Provide either base_dir or dir, but not both")
if base_dir is not None:
dir = os.path.join(base_dir, _create_random_id())
if dir is None:
raise ValueError("Provide either base_dir or dir")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either supply a dir or a base_dir

@magland magland changed the title implement lindi.File, drop-in replacement for h5py.File that supports .lindi.json files based on extension implement lindi.File, drop-in replacement for h5py.File that supports .lindi.json files based on extension (4) May 9, 2024
.gitignore Show resolved Hide resolved
magland and others added 3 commits May 9, 2024 05:19
…range-error

catch chunk byte range error (5)
Add generation metadata to .lindi.json file writing (6)
Base automatically changed from write-json to main May 9, 2024 21:22
@magland magland merged commit b85b8cf into main May 9, 2024
4 checks passed
@magland magland deleted the lindi-file branch May 9, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants