|
1 | 1 | from collections import defaultdict |
2 | 2 | import io |
| 3 | +import json |
3 | 4 | import os |
4 | | -import xmltodict |
5 | | -import numpy as np |
| 5 | +import sys |
| 6 | +import time |
6 | 7 | import warnings |
| 8 | + |
| 9 | +import numpy as np |
7 | 10 | import sklearn |
8 | | -import time |
9 | 11 | import six |
10 | | -import json |
| 12 | +import xmltodict |
11 | 13 |
|
12 | 14 | from ..exceptions import PyOpenMLError |
13 | 15 | from .. import config |
14 | | - |
15 | 16 | from ..flows import sklearn_to_flow, get_flow, flow_exists, _check_n_jobs |
16 | 17 | from ..setups import setup_exists, initialize_model |
17 | | - |
18 | 18 | from ..exceptions import OpenMLCacheException, OpenMLServerException |
19 | | -from ..util import URLError, version_complies |
20 | 19 | from .._api_calls import _perform_api_call, _file_id_to_url |
21 | 20 | from .run import OpenMLRun, _get_version_information |
22 | 21 | from .trace import OpenMLRunTrace, OpenMLTraceIteration |
|
26 | 25 | # circular imports |
27 | 26 |
|
28 | 27 |
|
29 | | - |
30 | 28 | def run_task(task, model, avoid_duplicate_runs=True, flow_tags=None, seed=None): |
31 | 29 | """Performs a CV run on the dataset of the given task, using the split. |
32 | 30 |
|
@@ -303,7 +301,9 @@ def _run_task_get_arffcontent(model, task, class_labels): |
303 | 301 | user_defined_measures = defaultdict(lambda: defaultdict(dict)) |
304 | 302 |
|
305 | 303 | rep_no = 0 |
306 | | - can_measure_runtime = version_complies(3, 3) and _check_n_jobs(model) |
| 304 | + # sys.version_info returns a tuple, the following line compares the entry of tuples |
| 305 | + # https://docs.python.org/3.6/reference/expressions.html#value-comparisons |
| 306 | + can_measure_runtime = sys.version_info[:2] >= (3, 3) and _check_n_jobs(model) |
307 | 307 | # TODO use different iterator to only provide a single iterator (less |
308 | 308 | # methods, less maintenance, less confusion) |
309 | 309 | for rep in task.iterate_repeats(): |
@@ -465,23 +465,13 @@ def get_run(run_id): |
465 | 465 |
|
466 | 466 | try: |
467 | 467 | return _get_cached_run(run_id) |
468 | | - except (OpenMLCacheException): |
469 | | - try: |
470 | | - run_xml = _perform_api_call("run/%d" % run_id) |
471 | | - except (URLError, UnicodeEncodeError) as e: |
472 | | - # TODO logger.debug |
473 | | - print(e) |
474 | | - raise e |
475 | 468 |
|
| 469 | + except (OpenMLCacheException): |
| 470 | + run_xml = _perform_api_call("run/%d" % run_id) |
476 | 471 | with io.open(run_file, "w", encoding='utf8') as fh: |
477 | 472 | fh.write(run_xml) |
478 | 473 |
|
479 | | - try: |
480 | | - run = _create_run_from_xml(run_xml) |
481 | | - except Exception as e: |
482 | | - # TODO logger.debug |
483 | | - print("Run ID", run_id) |
484 | | - raise e |
| 474 | + run = _create_run_from_xml(run_xml) |
485 | 475 |
|
486 | 476 | with io.open(run_file, "w", encoding='utf8') as fh: |
487 | 477 | fh.write(run_xml) |
|
0 commit comments