trevismd / statannotations

add statistical significance annotations on seaborn plots. Further development of statannot, with bugfixes, new features, and a different API.
Other
624 stars 67 forks source link

Added unit test to test labelling with floats on the x_axis #84

Closed JasonMendoza2008 closed 1 year ago

JasonMendoza2008 commented 1 year ago

To enhance tests for float values on the x_axis (they are currently supported). Also added PyCharm IDE files to the .gitignore file to avoid accidental commit of these files. Refers to this issue: https://github.com/trevismd/statannotations/issues/65

Not sure if the test is properly coded (EDIT: second commit should make the whole thing closer to what was already in place). In case the commit is not clear, here is the code (user-oriented) to create the figure and make sure the result is the one expected that I used as inspiration to make the unit test (I checked it did not run and now runs with your latest commits):

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
from statannotations.Annotator import Annotator

y_axis = [16.99, 10.34, 21.01, 23.68, 24.59, 25.29, 8.77, 26.88, 15.04, 14.78, 10.27, 35.26, 15.42, 18.43, 14.83, 21.58,
          10.33, 16.29, 16.97, 20.65, 17.92, 20.29, 15.77, 39.42, 19.82, 17.81, 13.37, 12.69, 21.7, 19.65, 9.55, 18.35,
          15.06, 20.69, 17.78, 24.06, 16.31, 16.93, 18.69, 31.27, 16.04, 17.46, 13.94, 9.68, 30.4, 18.29, 22.23, 32.4,
          28.55, 18.04]
x_axis = [1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03,
          1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03,
          1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02, 1.03, 1.01, 1.02]
df = pd.DataFrame(data={"y_axis": y_axis, "x_axis": x_axis})
x = "x_axis"
y = "y_axis"
order = [1.01, 1.02, 1.03]

ax = sns.boxplot(data=df, x=x, y=y, order=order)

pairs = [(1.01, 1.02), (1.02, 1.03)]

annotator = Annotator(ax, pairs, data=df, x=x, y=y, order=order)
annotator.configure(test='Mann-Whitney', text_format='star', loc='outside')
annotator.apply_and_annotate()
plt.savefig('test.png', dpi=300, bbox_inches='tight')
codecov[bot] commented 1 year ago

Codecov Report

Merging #84 (ace2592) into dev (c123a61) will increase coverage by 0.01%. The diff coverage is 100.00%.

:exclamation: Current head ace2592 differs from pull request most recent head 45cfdc5. Consider uploading reports for the commit 45cfdc5 to get more accurate results

@@            Coverage Diff             @@
##              dev      #84      +/-   ##
==========================================
+ Coverage   97.04%   97.06%   +0.01%     
==========================================
  Files          29       29              
  Lines        1898     1907       +9     
==========================================
+ Hits         1842     1851       +9     
  Misses         56       56              
Impacted Files Coverage Δ
tests/test_annotator.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

JasonMendoza2008 commented 1 year ago

Hello @trevismd I have squashed all commits and restored the blank line. For some reason I had to use the terminal and not PyCharm to squash the commits and to force push because they were greyed out in my IDE. Do you have any idea why that's the case? It's the first time that that's happening to me.

JasonMendoza2008 commented 1 year ago

@trevismd anything I should do? Tests failed on Python 3.6 but it seems to be github related.

trevismd commented 1 year ago

Thank you for your contribution and patience, @JasonMendoza2008 ! The problem is due to the availability of Python 3.6 in Ubuntu 22.04. I've already pushed a commit for it to the dev branch so this should work fine. (Finally, I'm afraid I can't come up with any idea about your squashing issue)