Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions statannotations/PValueFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'simple_format_string',
'text_format',
'pvalue_thresholds',
'show_test_name'
'show_test_name',
'p_capitalized'
]


Expand All @@ -38,6 +39,7 @@ def __init__(self):
self._pvalue_thresholds = self._get_pvalue_thresholds(DEFAULT)
self._correction_format = "{star} ({suffix})"
self.show_test_name = True
self.p_capitalized = False

def config(self, **parameters):

Expand Down Expand Up @@ -176,8 +178,10 @@ def format_data(self, result):
text = (f"{result.test_short_name} " if self.show_test_name
else "")

return ("{}p = {}{}"
.format('{}', self.pvalue_format_string, '{}')
p_letter = "P" if self.p_capitalized else "p"

return ("{}{} = {}{}"
.format('{}', p_letter, self.pvalue_format_string, '{}')
.format(text, result.pvalue, result.significance_suffix))

elif self.text_format == 'star':
Expand All @@ -199,7 +203,7 @@ def format_data(self, result):
# elif self.text_format == 'simple':
else:
return simple_text(result, self.simple_format_string,
self.pvalue_thresholds, self.show_test_name)
self.pvalue_thresholds, self.show_test_name, self.p_capitalized)

def get_configuration(self):
return {key: getattr(self, key) for key in CONFIGURABLE_PARAMETERS}
Expand Down
8 changes: 5 additions & 3 deletions statannotations/format_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def pval_annotation_text(result: List[StatResult],


def simple_text(result: StatResult, pvalue_format, pvalue_thresholds,
short_test_name=True) -> str:
short_test_name=True, p_capitalized=False) -> str:
"""
Generates simple text for test name and pvalue.

Expand All @@ -51,11 +51,13 @@ def simple_text(result: StatResult, pvalue_format, pvalue_thresholds,
if short_test_name and result.test_short_name
else "")

p_letter = "P" if p_capitalized else "p"

for threshold in thresholds:
if result.pvalue < threshold[0]:
pval_text = "p ≤ {}".format(threshold[1])
pval_text = "{} ≤ {}".format(p_letter, threshold[1])
break
else:
pval_text = "p = {}".format(pvalue_format).format(result.pvalue)
pval_text = "{} = {}".format(p_letter, pvalue_format).format(result.pvalue)

return result.adjust(text + pval_text)
17 changes: 17 additions & 0 deletions tests/test_pvalue_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_get_configuration(self):
self.assertDictEqual(pvalue_format.get_configuration(),
{'correction_format': '{star} ({suffix})',
'fontsize': 'medium',
'p_capitalized': False,
'pvalue_format_string': '{:.3e}',
'show_test_name': True,
'simple_format_string': '{:.2f}',
Expand All @@ -137,3 +138,19 @@ def test_config_pvalue_thresholds(self):
" ns: 5.00e-02 < p <= 1.00e+00\n"
" <= 0.05: 1.00e-03 < p <= 5.00e-02\n"
"<= 0.001: p <= 1.00e-03\n\n")

def test_pvalue_simple_capitalized(self):
self.annotator.configure(pvalue_format={"text_format": "simple",
"p_capitalized": True})
annotations = self.annotator._get_results("auto", pvalues=self.pvalues)
self.assertEqual(["P ≤ 0.05", "P ≤ 0.05", "P = 0.90"],
[annotation.text for annotation in annotations])

def test_pvalue_full_capitalized(self):
self.annotator.configure(pvalue_format={"text_format": "full",
"p_capitalized": True,
"show_test_name": False,
"pvalue_format_string": "{:.2f}"})
annotations = self.annotator._get_results("auto", pvalues=self.pvalues)
self.assertEqual(["P = 0.04", "P = 0.03", "P = 0.90"],
[annotation.text for annotation in annotations])
Loading