Skip to content

Fix / Unit tests test_violin and test_pbmc3k - #1422

Merged
fidelram merged 6 commits into
scverse:masterfrom
WeilerP:fix/unit_tests_test_violin_and_test_pbmc3k
Sep 22, 2020
Merged

fidelram merged 6 commits into
scverse:masterfrom
WeilerP:fix/unit_tests_test_violin_and_test_pbmc3k

Conversation

@WeilerP

@WeilerP WeilerP commented Sep 17, 2020

Copy link
Copy Markdown
Contributor

Description

As briefly outlined in #1420, using seaborn==0.11 causes the unit tests scanpy/tests/test_plotting.py:test_violin and scanpy/tests/notebooks/test_pbmc3k.py fail as the violin plots are no longer vertically oriented.

Changes

  • Rely on seaborn.catplot and seaborn.stripplot instead of seaborn.FacetGrid in scanpy/plotting/_anndata.py

Related issues

Closes #1420.

When using `seaborn==0.11`, the vertical orientation is ignored when
only `x` is specified. To orientate the violin plot vertically,
`seaborn.catplot` can be used instead of `seaborn.FacetGrid`.
The keyword arguments `"cut"` and `"inner"` cannot be passed to
`seaborn.catplot` or `seaborn.stripplot` and are thus moved to the
`else` clause.
Following the changes in `_anndata.py`, the PNG file generated by
`test_plotting.py:test_violin` has to be updated.
Following the changes in `_anndata.py`, the PNG file generated by
`test_pbmc3k.py:test_pbmc3k` has to be updated.
@WeilerP

WeilerP commented Sep 17, 2020

Copy link
Copy Markdown
Contributor Author

@fidelram, from seaborn==0.12 on, the only valid positional argument will be data which may cause failures or unexpected behaviour. This is relevant at least here and here. Should we add / specify the keyword argument x in this PR or open a separate issue and PR?

@fidelram

Copy link
Copy Markdown
Collaborator

@WeilerP Thanks for finding about this. Yes, please add explicitly x=x in this PR 👍

Pass `x` as a keyword argument to `seaborn.violinplot` and
`seaborn.stripplot`.
This supresses seaborn's FutureWarning "From version 0.12, the only
valid positional argument will be `data`, and passing other arguments
without an explicit keyword will result in an error or
misinterpretation."
@fidelram

Copy link
Copy Markdown
Collaborator

Thanks. Any idea why the images are now bigger (which I assume is the reason for the very small fonts)?

Pass keyword arguments `scale`, `cut` and `inner` to `seaborn.catplot`.
@WeilerP

WeilerP commented Sep 18, 2020

Copy link
Copy Markdown
Contributor Author

Hm, no sorry, I don't. My best guess would be that seaborn.catplot and seaborn.FacetGrid use different default figure sizes which in turn makes the font look smaller?

@WeilerP

WeilerP commented Sep 18, 2020

Copy link
Copy Markdown
Contributor Author

I noticed, however, that the tests pass even when removing the if stripplot: part. Any idea on why this is happening and how to prevent it?

@fidelram

Copy link
Copy Markdown
Collaborator

The tests have a tolerance parameter that is set high. The problem is that the stripplot shows different results each time. Also, different versions of matplotlib and seaborn have slight differences.

@fidelram

Copy link
Copy Markdown
Collaborator

I wonder why the tests are not working now?

Following the latest changes to `_anndata.py`, the expected PNG file
generated by `test_pbmc3k.py:test_pbmc3k` is updated.
@WeilerP

WeilerP commented Sep 22, 2020

Copy link
Copy Markdown
Contributor Author

I wonder why the tests are not working now?

Sorry, I forgot to update violin.png after the latest changes to _anndata.py. Let's see if the tests pass now.

@WeilerP

WeilerP commented Sep 22, 2020

Copy link
Copy Markdown
Contributor Author

The tests have a tolerance parameter that is set high. The problem is that the stripplot shows different results each time. Also, different versions of matplotlib and seaborn have slight differences.

Ah yes, I see. The stripplot result could be fixed by setting a seed with np.random.seed. I doubt it will fix the difference due to the used version, though.

@hhhh1230511

Copy link
Copy Markdown

Hi Developers,

I got the same issue when using seaborn==0.11, and fortunately I got the issue solved by replacing the annotate.py with the modified version. Howerver, I was wondering why I tried to use 'pip install scanpy' to update the scripts, it failed? Is there any other easier method to modify the script, not to locate the file and replace it?

@WeilerP
WeilerP deleted the fix/unit_tests_test_violin_and_test_pbmc3k branch November 26, 2020 19:48
@WeilerP

WeilerP commented Nov 26, 2020

Copy link
Copy Markdown
Contributor Author

@hhhh1230511, this PR is not part of any release yet (the latest version scanpy==1.6 was released August 15, 2020). If you want to have the latest version from GitHub you can follow the instructions for a developer installation here in the documentation, for example. Once a new release is available on pip, you can install it via pip install --upgrade scanpy
In general, you should avoid modifying the code by e.g. simply copying and pasting. This will either easily cause conflicts when updating the package or cause problems when functions from other files which depend on the content you changed but were not updated accordingly.

Hope this helped and clarified things.

@ivirshup ivirshup added the Maint – Backport needed Needs back porting for bugfix release label Dec 7, 2020
@ivirshup ivirshup removed the Maint – Backport needed Needs back porting for bugfix release label Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit tests fail with latest version of seaborn

4 participants