fix table name and add unit test for colors passed via .uns#413
fix table name and add unit test for colors passed via .uns#413ArneDefauw wants to merge 13 commits intoscverse:mainfrom
Conversation
for more information, see https://pre-commit.ci
…ot into fix_table_name
for more information, see https://pre-commit.ci
…ot into fix_table_name
|
Hi @ArneDefauw, thanks for the contribution. Two initial comments:
Thanks! |
|
Hi @LucaMarconato , I've linked an issue #414. For the failed unit tests, there was a KeyError, because I overlooked that For me all unit tests fail locally on the main branch of spatialdata-plot, so it is difficult to test. Therfore, I did not include base images for the unit tests I've added, because they would probably fail anyway in the CI/CD testing environment. The unit tests I've added are for documentation of the issue, some of them can probably be removed when merging to main. |
|
Thanks for updating the PR! Regarding the failing tests, could you please give a try to the approach described here? https://github.com/scverse/spatialdata-plot/blob/main/docs/contributing.md Locally generally the tests are reproducible on Ubuntu, but for other OS I use a Docker image, as described in the link above. |
|
My configuration with PyCharm is described here #397. |
for more information, see https://pre-commit.ci
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #413 +/- ##
==========================================
+ Coverage 83.83% 84.23% +0.40%
==========================================
Files 8 8
Lines 1732 1732
==========================================
+ Hits 1452 1459 +7
+ Misses 280 273 -7
|
|
I managed to fix the tests (using a centOS server). Note that I had to move this line inside , respectivelyto have the same results when running one test versus all the tests, because its internal state was moving forward due to multiple calls to it. Because of this I also had to update this figure https://github.com/scverse/spatialdata-plot/blob/main/tests/_images/Labels_can_annotate_labels_with_table_layer.png |
|
Fantastic! Thanks a lot! |
|
Closed in favour of #492 Thank you for the work @ArneDefauw! Only closing this one because I couldn't rebase your fork on the current main branch |
spatialdata_plot.pl.render._render_labelsstill hadsdata.table, changed tosdata.tables[table_name], otherwise colors passed via .uns where ignored.also in
spatialdata-plot/src/spatialdata_plot/pl/utils.py
Line 854 in 43f25f6
I would remove the check
cluster_keyinadata.uns. Because of this I had to setas a placeholder in https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L219 .
I also stumbled upon a subtle bug while testing this feature. With the small fix in this PR, one can pass colors via .uns[ f"{cluster_key}_colors" ], and all works as expected, see
https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L219
We get:

But if we do a bounding box query, we get:

While we expect:

In short, this is caused by https://github.com/scverse/spatialdata/blob/03d3be80fad69ff54097e90a9e80ad02e9e0e242/src/spatialdata/_utils.py#L203
also see scverse/anndata#997
For details see https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L227 and possible workaround https://github.com/ArneDefauw/spatialdata-plot/blob/b5cb0260c32a859783f87f10b8af05dc26feab76/tests/pl/test_render_labels.py#L252
Note that being able to plot a subset in the same colors as the orignal is a rather common use case. However, I am not sure where to fix. Maybe documenting the workaround suffices for now.