Helper function to sanitize tables#935
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #935 +/- ##
==========================================
+ Coverage 92.11% 92.14% +0.03%
==========================================
Files 48 48
Lines 7429 7473 +44
==========================================
+ Hits 6843 6886 +43
- Misses 586 587 +1
🚀 New features to boost your workflow:
|
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull Request Overview
This PR introduces helper functions to sanitize table keys in AnnData objects and updates validation error messaging to guide users in fixing naming issues.
- Adds sanitize_name and sanitize_table in src/spatialdata/_utils.py
- Provides comprehensive tests in tests/utils/test_sanitize.py to validate various sanitization scenarios
- Updates error messages in src/spatialdata/_core/validation.py to include a remediation hint
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/utils/test_sanitize.py | Adds tests covering multiple sanitization edge cases |
| src/spatialdata/_utils.py | Implements core sanitization logic for AnnData objects |
| src/spatialdata/_core/validation.py | Updates ValidationError messaging with sanitization suggestion |
Comments suppressed due to low confidence (1)
src/spatialdata/_core/validation.py:382
- The error message now suggests running 'spatialdata.utils.sanitize_table(adata)'. Please verify that the module reference accurately reflects the actual location or re-export of the sanitize_table function.
raise ValidationError(
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
LucaMarconato
left a comment
There was a problem hiding this comment.
Thanks Tim for implementing this functionality! I corrected an edge case, made the docstring more explicit (by referencing the naming restrictions #707) and added the functions to the docs.
Please give a review of my changes and feel free to merge.
|
There was an edge case around the user of
Also, now I sanitize |
|
|
||
| def sanitize_table(data: AnnData, inplace: bool = True) -> AnnData | None: | ||
| """ | ||
| Sanitize all keys in an AnnData table to comply with SpatialData naming rules. |
There was a problem hiding this comment.
We should maybe have a doc on these naming rules unless we had one already. WDYT @LucaMarconato
There was a problem hiding this comment.
Yes, at some point we will make a doc (when working on better documenting the file format). For the moment I added a link to #707.
melonora
left a comment
There was a problem hiding this comment.
Overall looks good to me, but here and there some minor requests.
melonora
left a comment
There was a problem hiding this comment.
After applying changes based on discussion with @LucaMarconato
|
Thanks great fixes, I agree with all the changes. |
No description provided.