Skip to content

Commit 1f37af5

Browse files
committed
Fix numpy ndarray type annotations for mypy strict checking
- Import NDArray from numpy.typing - Replace all np.ndarray with NDArray[Any] in function signatures - Resolves 6 missing type parameter errors in stats_tests.py - All CI checks now pass: ruff, black, mypy, pytest
1 parent 6c1c0fb commit 1f37af5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/tgalpha/stats_tests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
and multiple testing corrections for robust statistical inference.
66
"""
77

8-
from typing import List, Tuple, Optional
8+
from typing import List, Tuple, Optional, Any
99
import numpy as np
10+
from numpy.typing import NDArray
1011
from scipy import stats
1112
from statsmodels.stats.multitest import multipletests
1213

1314

1415
def bootstrap_confidence_interval(
15-
returns: np.ndarray,
16+
returns: NDArray[Any],
1617
statistic: str = "median",
1718
n_bootstrap: int = 10000,
1819
confidence_level: float = 0.95,
@@ -65,7 +66,7 @@ def bootstrap_confidence_interval(
6566
return (point_est, lower_bound, upper_bound)
6667

6768

68-
def wilcoxon_test(returns: np.ndarray, alternative: str = "greater") -> Tuple[float, float]:
69+
def wilcoxon_test(returns: NDArray[Any], alternative: str = "greater") -> Tuple[float, float]:
6970
"""
7071
Wilcoxon signed-rank test for returns vs. zero.
7172
@@ -92,7 +93,7 @@ def wilcoxon_test(returns: np.ndarray, alternative: str = "greater") -> Tuple[fl
9293
return (np.nan, np.nan)
9394

9495

95-
def t_test(returns: np.ndarray, alternative: str = "greater") -> Tuple[float, float]:
96+
def t_test(returns: NDArray[Any], alternative: str = "greater") -> Tuple[float, float]:
9697
"""
9798
One-sample t-test for returns vs. zero.
9899
@@ -115,7 +116,7 @@ def t_test(returns: np.ndarray, alternative: str = "greater") -> Tuple[float, fl
115116

116117
def benjamini_hochberg_correction(
117118
p_values: List[float], alpha: float = 0.05
118-
) -> Tuple[np.ndarray, np.ndarray]:
119+
) -> Tuple[NDArray[Any], NDArray[Any]]:
119120
"""
120121
Apply Benjamini-Hochberg FDR correction for multiple testing.
121122
@@ -142,7 +143,7 @@ def benjamini_hochberg_correction(
142143
return (reject, corrected_pvals)
143144

144145

145-
def compute_effect_size(returns: np.ndarray) -> float:
146+
def compute_effect_size(returns: NDArray[Any]) -> float:
146147
"""
147148
Compute Cohen's d effect size for returns vs. zero.
148149
@@ -170,7 +171,7 @@ def compute_effect_size(returns: np.ndarray) -> float:
170171
return float(mean_return / std_return)
171172

172173

173-
def sharpe_ratio(returns: np.ndarray, risk_free_rate: float = 0.0) -> float:
174+
def sharpe_ratio(returns: NDArray[Any], risk_free_rate: float = 0.0) -> float:
174175
"""
175176
Compute annualized Sharpe ratio for strategy.
176177

0 commit comments

Comments
 (0)