Skip to content

Commit 097766a

Browse files
author
Vianney Taquet
committed
Take previous PRs into account
1 parent 71fc1d6 commit 097766a

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

mapie/estimators.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Optional, Union, Iterable
2+
from typing import Optional, Union, Iterable, Tuple, List
33

44
import numpy as np
55
from joblib import Parallel, delayed
@@ -239,7 +239,6 @@ def _check_cv(self, cv: Optional[Union[int, BaseCrossValidator]] = None) -> Base
239239
return cv
240240
raise ValueError("Invalid cv argument. Allowed values are None, -1, int >= 2, KFold or LeaveOneOut.")
241241

242-
243242
def _check_alpha(self, alpha: Union[float, Iterable[float]]) -> np.ndarray:
244243
"""
245244
Check alpha and prepare it as a np.ndarray
@@ -273,7 +272,6 @@ def _check_alpha(self, alpha: Union[float, Iterable[float]]) -> np.ndarray:
273272
raise ValueError("Invalid alpha. Please provide a one-dimensional list of values.")
274273
if alpha_np.dtype.type not in [np.float64, np.float32]:
275274
raise ValueError("Invalid alpha. Allowed values are Iterable of floats.")
276-
277275
if np.any((alpha_np <= 0) | (alpha_np >= 1)):
278276
raise ValueError("Invalid alpha. Allowed values are between 0 and 1.")
279277
return alpha_np

mapie/tests/test_estimators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def test_linear_regression_results(strategy: str) -> None:
308308

309309

310310
@pytest.mark.parametrize("strategy", [*STRATEGIES])
311-
def test_results_for_same_alpha(strategy: str, alpha: Any) -> None:
311+
def test_results_for_same_alpha(strategy: str) -> None:
312312
"""Test that predictions and intervals are similar with two equal values of alpha."""
313313
mapie = MapieRegressor(alpha=[0.1, 0.1], **STRATEGIES[strategy])
314314
mapie.fit(X_reg, y_reg)
@@ -341,6 +341,8 @@ def test_results_for_alpha_as_float_and_arraylike(strategy: str, alpha: Any) ->
341341
np.testing.assert_almost_equal(y_preds_float1[:, :, 0], y_preds_array[:, :, 0], 7)
342342
np.testing.assert_almost_equal(y_preds_float2[:, :, 0], y_preds_array[:, :, 1], 7)
343343

344+
345+
@pytest.mark.parametrize("strategy", [*STRATEGIES])
344346
def test_results_single_and_multi_jobs(strategy: str) -> None:
345347
"""
346348
Test that MapieRegressor gives equal predictions regardless of number of parallel jobs.
@@ -349,8 +351,6 @@ def test_results_single_and_multi_jobs(strategy: str) -> None:
349351
mapie_single.fit(X_toy, y_toy)
350352
mapie_multi = MapieRegressor(n_jobs=-1, **STRATEGIES[strategy])
351353
mapie_multi.fit(X_toy, y_toy)
352-
y_pred_single, y_low_single, y_up_single = mapie_single.predict(X_toy).T
353-
y_pred_multi, y_low_multi, y_up_multi = mapie_multi.predict(X_toy).T
354-
np.testing.assert_almost_equal(y_pred_single, y_pred_multi)
355-
np.testing.assert_almost_equal(y_low_single, y_low_multi)
356-
np.testing.assert_almost_equal(y_up_single, y_up_multi)
354+
y_preds_single = mapie_single.predict(X_toy)
355+
y_preds_multi = mapie_multi.predict(X_toy)
356+
np.testing.assert_almost_equal(y_preds_single, y_preds_multi, 7)

0 commit comments

Comments
 (0)