chore: fix spatialdata access in squidpy via a helper function#1134
chore: fix spatialdata access in squidpy via a helper function#1134selmanozleyen wants to merge 29 commits into
Conversation
efc8ac1 to
40dad3e
Compare
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1134 +/- ##
==========================================
+ Coverage 73.82% 74.20% +0.38%
==========================================
Files 45 45
Lines 7013 7016 +3
Branches 1188 1179 -9
==========================================
+ Hits 5177 5206 +29
+ Misses 1349 1332 -17
+ Partials 487 478 -9
🚀 New features to boost your workflow:
|
| backend: str = "loky", | ||
| show_progress_bar: bool = True, | ||
| *, | ||
| table_key: str = "table", |
There was a problem hiding this comment.
This is no longer convention in SpatialData due to inherently multi-table techs like VisiumHD or CosMx 🤔 But it might be good to just let the user run into the error msg that tells them about their options if they don't specify it so I think we can leave it like this
There was a problem hiding this comment.
isn’t using "table" as default misleading then?
| return adata, library_key | ||
|
|
||
| assert elements_to_coordinate_systems is not None, ( | ||
| "Since `adata` is a :class:`spatialdata.SpatialData`, `elements_to_coordinate_systems` must not be `None`." |
There was a problem hiding this comment.
"adata is sdata" is weird? Maybe it should be resolve_data/input?
There was a problem hiding this comment.
yes but the error message would still have to be the same since the public signature takes adata, otherwise the error message would be confusing
There was a problem hiding this comment.
this is done in many places lets make an issue about it and move on for here. Ideally we would call it data since it's positional argument anyway
flying-sheep
left a comment
There was a problem hiding this comment.
Looks great apart from the table issue: #1134 (comment)
I think since there’s no default anymore, it might make sense to require specifying table=... when adata is a SpatialData (and raise a TypeError otherwise, as Python does when a required parameter is missing)
|
Thank you @flying-sheep ! Also what do you think of changing the parameter name from |
|
Makes sense to me! Make sure to add a And put the I think most good APIs have 1–2 positional-only parameters (might have defaults), and some keyword-only parameters that all have defaults. Most functions have zero positional-or-keyword parameters, but for some it makes sense. e.g. def var_by_distance(
adata: AnnData,
groups: str | list[str] | NDArrayA,
/,
*,
cluster_key: str | None = None,
...
) -> ...:whereas def nhood_enrichment(
data: AnnData | SpatialData,
/,
cluster_key: str,
*,
library_key: str | None = None,
connectivity_key: str | None = None,
...
) -> ...: |
Fixes #1133 and implements the table extraction in a decorator so we won't need to ctrl+f our way to fix a similar bug when it happens
update: decided not to use a decorator as it uses metaprogramming with little to no benefit over using a function. Only plus was not adding
table_keyto the signature which isn't a plus imo. Explicitly typing a signature of a function is not something I consider as duplicate code