|
1 | 1 | """ChiSquareTest (Chi-square test) module.""" |
2 | 2 |
|
3 | 3 | import collections |
4 | | -from typing import Optional, Tuple, Union |
| 4 | +import typing |
| 5 | +from typing import Optional, Set, Tuple, Union |
5 | 6 |
|
6 | 7 | import numpy as np # type: ignore |
7 | 8 | from scipy.stats import chi2_contingency # type: ignore |
@@ -77,19 +78,20 @@ def _statistical_test( |
77 | 78 | return test |
78 | 79 |
|
79 | 80 | @staticmethod |
| 81 | + @typing.no_type_check # FIXME: X_ref_counter and X_counter cause mypy errors # pylint: disable=fixme # noqa: E501 |
80 | 82 | def _calculate_frequencies( |
81 | 83 | X_ref: np.ndarray, # noqa: N803 |
82 | 84 | X: np.ndarray, |
83 | 85 | ) -> Tuple[list[int], list[int]]: |
84 | 86 | X_ref_counter, X_counter = [ # noqa: N806 |
85 | 87 | *map(collections.Counter, [X_ref, X]) # noqa: N806 |
86 | 88 | ] |
87 | | - possible_values = set([*X_ref_counter.keys()] + [*X_counter.keys()]) |
| 89 | + possible_values: Set[str] = set( |
| 90 | + [*X_ref_counter.keys()] + [*X_counter.keys()] |
| 91 | + ) # noqa: N806 |
88 | 92 | f_exp, f_obs = {}, {} |
89 | 93 | for value in possible_values: |
90 | | - f_exp[value] = X_ref_counter.get(value, 0) |
91 | | - f_obs[value] = X_counter.get(value, 0) |
92 | | - f_exp_values, f_obs_values = [ |
93 | | - *map(list, [f_exp.values(), f_obs.values()]) # type: ignore |
94 | | - ] |
95 | | - return f_exp_values, f_obs_values # type: ignore |
| 94 | + f_exp[value] = X_ref_counter.get(value, 0) # noqa: N806 |
| 95 | + f_obs[value] = X_counter.get(value, 0) # noqa: N806 |
| 96 | + f_exp_values, f_obs_values = [*map(list, [f_exp.values(), f_obs.values()])] |
| 97 | + return f_exp_values, f_obs_values |
0 commit comments