Skip to content

Commit 22c19b1

Browse files
committed
Add type hints and consistent return type
1 parent 325f957 commit 22c19b1

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

pycalib/stats.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import namedtuple
12
import numpy as np
23
import pandas as pd
34

@@ -7,8 +8,11 @@
78
from scipy.stats import friedmanchisquare
89

910

10-
def compute_friedmanchisquare(table):
11-
'''
11+
TestResult = namedtuple("TestResult", ["statistic", "p_value"])
12+
13+
14+
def compute_friedmanchisquare(table: pd.DataFrame) -> TestResult:
15+
""" Compute Friedman test for repeated samples
1216
Example:
1317
- n wine judges each rate k different wines. Are any of the k wines
1418
ranked consistently higher or lower than the others?
@@ -19,21 +23,17 @@ def compute_friedmanchisquare(table):
1923
This will output a statistic and a p-value
2024
SciPy does the following:
2125
- k: is the number of parameters passed to the function
22-
- n: is the lenght of each array passed to the function
26+
- n: is the length of each array passed to the function
2327
The two options for the given table are:
24-
- k is the datasets: table['mean'].values).tolist()
25-
- k is the calibration methods: table['mean'].T.values).tolist()
26-
'''
28+
- k is the datasets: table['mean'].values.tolist()
29+
- k is the calibration methods: table['mean'].T.values.tolist()
30+
"""
2731
if table.shape[1] < 3:
28-
print('Friedman test not appropiate for less than 3 methods')
29-
30-
class Ftest():
31-
def __init__(self, statistic, pvalue):
32-
self.statistic = statistic
33-
self.pvalue = pvalue
34-
return Ftest(np.nan, np.nan)
32+
print('Friedman test not appropriate for less than 3 methods')
33+
return TestResult(np.nan, np.nan)
3534

36-
return friedmanchisquare(*(table.T.values).tolist())
35+
statistic, p = friedmanchisquare(*table.T.values)
36+
return TestResult(statistic, p)
3737

3838

3939
def paired_test(table, stats_func=ranksums):

0 commit comments

Comments
 (0)