Add to_scipy_sparse/from_scipy_sparse xarray accessor methods - #1621
Open
aroaxinping wants to merge 3 commits into
Open
Add to_scipy_sparse/from_scipy_sparse xarray accessor methods#1621aroaxinping wants to merge 3 commits into
aroaxinping wants to merge 3 commits into
Conversation
Converts between a 2-dimensional DataArray and a scipy.sparse matrix via the sparse package's COO format. Adds sparse as a new optional extra, following the same try/except pattern already used for biopython/tqdm in biology.py/chemistry.py.
CI failed because pixi.lock was out of sync with the new sparse optional-dependency entries in pyproject.toml. Regenerated the lock file, and added a dedicated pixi feature/environment for sparse (mirroring biology/chemistry/engineering/spark), since the default test environments don't install optional domain packages. Also added the same skipif guard used in tests/biology and tests/chemistry, so the new tests skip cleanly instead of erroring in environments where sparse isn't installed.
Same issue as the pytest failures: the docstring examples for to_scipy_sparse/from_scipy_sparse call sparse-backed code directly, so they fail with NameError in environments where sparse isn't installed (the default test environments, matching biopython/tqdm). Marked the affected lines +SKIP, same as join_fasta's docstring in biology.py.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #1621 +/- ##
==========================================
- Coverage 87.56% 85.82% -1.74%
==========================================
Files 95 125 +30
Lines 6819 9928 +3109
==========================================
+ Hits 5971 8521 +2550
- Misses 848 1407 +559 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #636
What
Adds
to_scipy_sparseandfrom_scipy_sparseas xarray DataArrayaccessor methods, converting between a 2D DataArray and a
scipy.sparsematrix via thesparsepackage's COO format.Heads up: new optional dependency
This pulls in
sparseas a new optional extra (pip install pyjanitor[sparse]) — nothing changes for anyone who doesn't use it.Followed the same try/except pattern already used for biopython/tqdm
in biology.py/chemistry.py: without
sparseinstalled,import janitorstill works fine, you just get a warning, and only callingthe new functions raises an error.
Notes
from_scipy_sparsewasn't in the original issue, only theto_direction had a sketch. I built it as a thin wrapper around the
existing
clone_using, since a scipy sparse matrix generally won'tshare
da's shape — happy to change the API if you had somethingdifferent in mind.
sparseinstalled either way,import janitordoesn't break.