-
Notifications
You must be signed in to change notification settings - Fork 4
Implement readers for compressed lists #68
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 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
11c4a01
Read compressed integer lists
jkanche 9a4ee89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ee482be
editable builds
jkanche a69cebb
bring actions upto date
jkanche 959dad1
remove prints, update test
jkanche 915b6f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5978c52
tests for compressed lists
jkanche 18e4458
Merge branch 'compressed-lists' of https://github.com/biocpy/rds2py i…
jkanche be5065c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 23f3abb
update changelog
jkanche 27e1e4c
Merge branch 'compressed-lists' of https://github.com/biocpy/rds2py i…
jkanche b2e0dc0
Merge remote-tracking branch 'origin/master' into compressed-lists
jkanche 838c37f
python 3.9 EOL
jkanche 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
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,84 @@ | ||
| """Functions and classes for parsing Compressed List data structures.""" | ||
|
|
||
| import numpy as np | ||
|
|
||
| from .generics import _dispatcher | ||
| from .rdsutils import get_class | ||
|
|
||
| __author__ = "jkanche" | ||
| __copyright__ = "jkanche" | ||
| __license__ = "MIT" | ||
|
|
||
|
|
||
| def read_partitioning_by_end(robject: dict, **kwargs): | ||
| """Read an partioning by end object. | ||
|
|
||
| Args: | ||
| robject: | ||
| Dictionary containing parsed partioning by end object. | ||
|
|
||
| **kwargs: | ||
| Additional arguments. | ||
|
|
||
| Returns: | ||
| A vector containing the partitions. | ||
| """ | ||
| _cls = get_class(robject) | ||
|
|
||
| if _cls not in ["PartitioningByEnd"]: | ||
| raise RuntimeError(f"`robject` does not contain not a `PartitioningByEnd` object, contains `{_cls}`.") | ||
|
|
||
| ends = _dispatcher(robject["attributes"]["end"], **kwargs) | ||
|
|
||
| from compressed_lists import Partitioning | ||
|
|
||
| return Partitioning(ends=np.asarray(ends)) | ||
|
|
||
|
|
||
| def read_compressed_integer_list(robject: dict, **kwargs): | ||
| """Read an R compressed list. | ||
|
|
||
| Args: | ||
| robject: | ||
| Dictionary containing parsed compressed list. | ||
|
|
||
| **kwargs: | ||
| Additional arguments. | ||
|
|
||
| Returns: | ||
| A `CompressedList` from the 'compressed_lists' package. | ||
| """ | ||
| _cls = get_class(robject) | ||
|
|
||
| if _cls not in ["CompressedIntegerList"]: | ||
| raise RuntimeError(f"`robject` does not contain not a compressed integer list object, contains `{_cls}`.") | ||
|
|
||
| if "unlistData" not in robject["attributes"]: | ||
| raise ValueError("Object does not contain unlistData, is it really a `compressedList`?") | ||
| unlist_data = _dispatcher(robject["attributes"]["unlistData"], **kwargs) | ||
|
|
||
| print("unlist_data", unlist_data) | ||
|
|
||
| element_metadata = None | ||
| if "elementMetadata" in robject["attributes"]: | ||
| element_metadata = _dispatcher(robject["attributes"]["elementMetadata"], **kwargs) | ||
|
|
||
| print("element_metadata", element_metadata) | ||
|
|
||
| metadata = None | ||
| if "metadata" in robject["attributes"]: | ||
| metadata = _dispatcher(robject["attributes"]["metadata"], **kwargs) | ||
|
|
||
| print("metadata", metadata) | ||
|
|
||
| partition = None | ||
| if "partitioning" in robject["attributes"]: | ||
| partition = _dispatcher(robject["attributes"]["partitioning"], **kwargs) | ||
|
|
||
| print("partition", partition) | ||
|
|
||
| from compressed_lists import CompressedIntegerList | ||
|
|
||
| return CompressedIntegerList( | ||
| unlist_data=unlist_data, partitioning=partition, element_metadata=element_metadata, metadata=metadata | ||
| ) |
Binary file not shown.
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,19 @@ | ||
| import pytest | ||
|
|
||
| from rds2py import read_rds | ||
| from compressed_lists import CompressedIntegerList | ||
|
|
||
| __author__ = "jkanche" | ||
| __copyright__ = "jkanche" | ||
| __license__ = "MIT" | ||
|
|
||
|
|
||
| def test_compressed_lists_int(): | ||
| obj = read_rds("tests/data/compressedlist_int.rds") | ||
|
|
||
| print(obj) | ||
|
|
||
| assert obj is not None | ||
| assert len(obj) > 0 | ||
|
|
||
| assert isinstance(obj, CompressedIntegerList) |
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.
Check warning
Code scanning / CodeQL
Unpinned tag for a non-immutable Action in workflow Medium