-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move definitions from test/facet/__init__ to test/conftest (#121)
- Loading branch information
Showing
5 changed files
with
50 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +0,0 @@ | ||
from typing import Any, List, Mapping, Optional, Sequence | ||
|
||
import pytest | ||
|
||
from facet.selection import LearnerEvaluation | ||
|
||
STEP_IMPUTE = "impute" | ||
STEP_ONE_HOT_ENCODE = "one-hot-encode" | ||
|
||
|
||
def check_ranking( | ||
ranking: List[LearnerEvaluation], | ||
expected_scores: Sequence[float], | ||
expected_learners: Optional[Sequence[type]], | ||
expected_parameters: Optional[Mapping[int, Mapping[str, Any]]], | ||
) -> None: | ||
""" | ||
Test helper to check rankings produced by learner rankers | ||
:param ranking: a list of LearnerEvaluations | ||
:param expected_scores: expected ranking scores, rounded to 3 decimal places | ||
:param expected_learners: expected learner classes | ||
:param expected_parameters: expected learner parameters | ||
:return: None | ||
""" | ||
|
||
if expected_learners is None: | ||
expected_learners = [None] * len(ranking) | ||
|
||
for rank, (learner_eval, score_expected, learner_expected) in enumerate( | ||
zip(ranking, expected_scores, expected_learners) | ||
): | ||
score_actual = round(learner_eval.ranking_score, 3) | ||
assert score_actual == pytest.approx(score_expected, abs=0.1), ( | ||
f"unexpected score for learner at rank #{rank + 1}: " | ||
f"got {score_actual} but expected {score_expected}" | ||
) | ||
if learner_expected is not None: | ||
learner_actual = learner_eval.pipeline.final_estimator | ||
assert type(learner_actual) == learner_expected, ( | ||
f"unexpected class for learner at rank #{rank}: " | ||
f"got {type(learner_actual)} but expected {learner_expected}" | ||
) | ||
|
||
if expected_parameters is not None: | ||
for rank, parameters_expected in expected_parameters.items(): | ||
parameters_actual = ranking[rank].parameters | ||
assert parameters_actual == parameters_expected, ( | ||
f"unexpected parameters for learner at rank #{rank}: " | ||
f"got {parameters_actual} but expected {parameters_expected}" | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters