-
Notifications
You must be signed in to change notification settings - Fork 0
Root attributes #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2bce366
Add function to ensure optional anndata groups in subset operations
Claptar 8553664
Add functions to ensure and validate AnnData root attributes in store…
Claptar 796e74c
Add tests for AnnData root encoding attributes enforcement and warnings
Claptar 4d44e46
Add test for optional empty groups in subset_h5ad function
Claptar 1911cdc
Refactor test_subset_h5ad to improve readability and ensure optional …
Claptar a62f6e0
Bump h5ad package version to 0.3.1
Claptar 7ba61c9
Update src/h5ad/storage/__init__.py
Claptar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Tests for AnnData root encoding attributes enforcement/warnings.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import h5py | ||
| import pytest | ||
|
|
||
| from h5ad.storage import open_store | ||
|
|
||
|
|
||
| def _make_minimal_h5ad(path: Path) -> None: | ||
| with h5py.File(path, "w") as f: | ||
| obs = f.create_group("obs") | ||
| obs.attrs["_index"] = "obs_names" | ||
| obs.create_dataset("obs_names", data=[b"cell_1"]) | ||
|
|
||
| var = f.create_group("var") | ||
| var.attrs["_index"] = "var_names" | ||
| var.create_dataset("var_names", data=[b"gene_1"]) | ||
|
|
||
| f.create_dataset("X", data=[[1.0]]) | ||
|
|
||
|
|
||
| def test_open_store_read_warns_for_missing_root_attrs(temp_dir: Path) -> None: | ||
| file_path = temp_dir / "missing_root_attrs.h5ad" | ||
| _make_minimal_h5ad(file_path) | ||
|
|
||
| with pytest.warns(UserWarning, match="missing required AnnData attrs"): | ||
| with open_store(file_path, "r"): | ||
| pass | ||
|
|
||
|
|
||
| def test_open_store_writable_mode_sets_root_attrs(temp_dir: Path) -> None: | ||
| file_path = temp_dir / "set_root_attrs.h5ad" | ||
| _make_minimal_h5ad(file_path) | ||
|
|
||
| with open_store(file_path, "a"): | ||
| pass | ||
|
|
||
| with h5py.File(file_path, "r") as f: | ||
| assert f.attrs.get("encoding-type") == "anndata" | ||
| assert f.attrs.get("encoding-version") == "0.1.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subset_h5adnow always createslayers/obsm/obsp/varm/varpwhen absent, but these groups are created without anyencoding-type/encoding-versionmetadata. In this codebase’s AnnData element docs, those members are mappings and mappings must carryencoding-type="dict"andencoding-version="0.1.0"; creating the groups without attrs turns previously-valid “absent optional member” outputs into malformed mapping groups, which can break schema-aware downstream readers/concat workflows.Useful? React with 👍 / 👎.