Skip to content

Commit 3fab583

Browse files
authored
shuffle around checks for type (#714)
* shuffle around checks for type * re-activate unit test * update function
1 parent 3905544 commit 3fab583

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

openml/runs/functions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ def run_model_on_task(
7878
Flow generated from the model.
7979
"""
8080

81-
extension = get_extension_by_model(model, raise_if_no_extension=True)
82-
if extension is None:
83-
# This should never happen and is only here to please mypy will be gone soon once the
84-
# whole function is removed
85-
raise TypeError(extension)
86-
8781
# TODO: At some point in the future do not allow for arguments in old order (6-2018).
8882
# Flexibility currently still allowed due to code-snippet in OpenML100 paper (3-2019).
8983
# When removing this please also remove the method `is_estimator` from the extension
9084
# interface as it is only used here (MF, 3-2019)
91-
if isinstance(model, OpenMLTask) and extension.is_estimator(model):
85+
if isinstance(model, OpenMLTask):
9286
warnings.warn("The old argument order (task, model) is deprecated and "
9387
"will not be supported in the future. Please use the "
9488
"order (model, task).", DeprecationWarning)
9589
task, model = model, task
9690

91+
extension = get_extension_by_model(model, raise_if_no_extension=True)
92+
if extension is None:
93+
# This should never happen and is only here to please mypy will be gone soon once the
94+
# whole function is removed
95+
raise TypeError(extension)
96+
9797
flow = extension.model_to_flow(model)
9898

9999
run = run_flow_on_task(
@@ -159,9 +159,6 @@ def run_flow_on_task(
159159
if flow_tags is not None and not isinstance(flow_tags, list):
160160
raise ValueError("flow_tags should be a list")
161161

162-
if task.task_id is None:
163-
raise ValueError("The task should be published at OpenML")
164-
165162
# TODO: At some point in the future do not allow for arguments in old order (changed 6-2018).
166163
# Flexibility currently still allowed due to code-snippet in OpenML100 paper (3-2019).
167164
if isinstance(flow, OpenMLTask) and isinstance(task, OpenMLFlow):
@@ -171,6 +168,9 @@ def run_flow_on_task(
171168
"order (model, Flow).", DeprecationWarning)
172169
task, flow = flow, task
173170

171+
if task.task_id is None:
172+
raise ValueError("The task should be published at OpenML")
173+
174174
flow.model = flow.extension.seed_model(flow.model, seed=seed)
175175

176176
# We only need to sync with the server right now if we want to upload the flow,

tests/test_runs/test_run_functions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ def _test_local_evaluations(self, run):
725725
self.assertGreaterEqual(alt_scores[idx], 0)
726726
self.assertLessEqual(alt_scores[idx], 1)
727727

728-
def test_local_run_metric_score_swapped_parameter_order_model(self):
728+
def test_local_run_swapped_parameter_order_model(self):
729729

730730
# construct sci-kit learn classifier
731731
clf = Pipeline(steps=[('imputer', Imputer(strategy='median')),
@@ -736,15 +736,14 @@ def test_local_run_metric_score_swapped_parameter_order_model(self):
736736

737737
# invoke OpenML run
738738
run = openml.runs.run_model_on_task(
739-
model=clf,
740-
task=task,
739+
task, clf,
741740
avoid_duplicate_runs=False,
742741
upload_flow=False,
743742
)
744743

745744
self._test_local_evaluations(run)
746745

747-
def test_local_run_metric_score_swapped_parameter_order_flow(self):
746+
def test_local_run_swapped_parameter_order_flow(self):
748747

749748
# construct sci-kit learn classifier
750749
clf = Pipeline(steps=[('imputer', Imputer(strategy='median')),
@@ -756,8 +755,7 @@ def test_local_run_metric_score_swapped_parameter_order_flow(self):
756755

757756
# invoke OpenML run
758757
run = openml.runs.run_flow_on_task(
759-
flow=flow,
760-
task=task,
758+
task, flow,
761759
avoid_duplicate_runs=False,
762760
upload_flow=False,
763761
)

0 commit comments

Comments
 (0)