Skip to content

Commit

Permalink
CHORE: make type checking stricter for v1 files (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Laurent committed Feb 4, 2025
1 parent ae349d1 commit 0c52ff4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type-check:
mypy mapie

v1-type-check:
mypy mapie_v1 --exclude $(mapie_v0_folder_name)
mypy mapie_v1 --disallow-untyped-defs --exclude $(mapie_v0_folder_name)

tests:
pytest -vs --doctest-modules mapie
Expand Down
2 changes: 1 addition & 1 deletion mapie_v1/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_if_param_in_allowed_values(
)


def check_cv_not_string(cv: Union[int, str, BaseCrossValidator]):
def check_cv_not_string(cv: Union[int, str, BaseCrossValidator]) -> None:
if isinstance(cv, str):
raise ValueError(
"'cv' string options not available in MAPIE >= v1"
Expand Down
18 changes: 11 additions & 7 deletions mapie_v1/integration_tests/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sklearn.model_selection import train_test_split

from mapie.subsample import Subsample
from mapie._typing import ArrayLike
from mapie._typing import ArrayLike, NDArray
from mapie.conformity_scores import GammaConformityScore, \
AbsoluteConformityScore, ResidualNormalisedScore
from mapie_v1.regression import SplitConformalRegressor, \
Expand Down Expand Up @@ -136,7 +136,7 @@


@pytest.mark.parametrize("params_split", params_test_cases_split)
def test_intervals_and_predictions_exact_equality_split(params_split):
def test_intervals_and_predictions_exact_equality_split(params_split: dict) -> None:
v0_params = params_split["v0"]
v1_params = params_split["v1"]

Expand Down Expand Up @@ -222,7 +222,7 @@ def test_intervals_and_predictions_exact_equality_split(params_split):


@pytest.mark.parametrize("params_cross", params_test_cases_cross)
def test_intervals_and_predictions_exact_equality_cross(params_cross):
def test_intervals_and_predictions_exact_equality_cross(params_cross: dict) -> None:

compare_model_predictions_and_intervals(
model_v0=MapieRegressorV0,
Expand Down Expand Up @@ -313,7 +313,9 @@ def test_intervals_and_predictions_exact_equality_cross(params_cross):


@pytest.mark.parametrize("params_jackknife", params_test_cases_jackknife)
def test_intervals_and_predictions_exact_equality_jackknife(params_jackknife):
def test_intervals_and_predictions_exact_equality_jackknife(
params_jackknife: dict
) -> None:

compare_model_predictions_and_intervals(
model_v0=MapieRegressorV0,
Expand Down Expand Up @@ -419,7 +421,9 @@ def test_intervals_and_predictions_exact_equality_jackknife(params_jackknife):


@pytest.mark.parametrize("params_quantile", params_test_cases_quantile)
def test_intervals_and_predictions_exact_equality_quantile(params_quantile):
def test_intervals_and_predictions_exact_equality_quantile(
params_quantile: dict
) -> None:
v0_params = params_quantile["v0"]
v1_params = params_quantile["v1"]

Expand Down Expand Up @@ -447,8 +451,8 @@ def compare_model_predictions_and_intervals(
JackknifeAfterBootstrapRegressor,
ConformalizedQuantileRegressor
]],
X: ArrayLike,
y: ArrayLike,
X: NDArray,
y: NDArray,
v0_params: Dict = {},
v1_params: Dict = {},
prefit: bool = False,
Expand Down
9 changes: 5 additions & 4 deletions mapie_v1/integration_tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import Callable, Dict, Any, Optional
from typing import Callable, Dict, Any, Optional, Tuple
from mapie._typing import NDArray
import inspect
from sklearn.model_selection import ShuffleSplit


def train_test_split_shuffle(
X,
y,
X: NDArray,
y: NDArray,
test_size: float = 0.2,
random_state: int = 42
):
) -> Tuple[Any, Any, Any, Any]:

splitter = ShuffleSplit(n_splits=1,
test_size=test_size,
Expand Down

0 comments on commit 0c52ff4

Please sign in to comment.