|
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 |
|
@@ -296,7 +294,9 @@ def _run_task_get_arffcontent(model, task, class_labels): |
296 | 294 | user_defined_measures = defaultdict(lambda: defaultdict(dict)) |
297 | 295 |
|
298 | 296 | rep_no = 0 |
299 | | - can_measure_runtime = version_complies(3, 3) and _check_n_jobs(model) |
| 297 | + # sys.version_info returns a tuple, the following line compares the entry of tuples |
| 298 | + # https://docs.python.org/3.6/reference/expressions.html#value-comparisons |
| 299 | + can_measure_runtime = sys.version_info[:2] >= (3, 3) and _check_n_jobs(model) |
300 | 300 | # TODO use different iterator to only provide a single iterator (less |
301 | 301 | # methods, less maintenance, less confusion) |
302 | 302 | for rep in task.iterate_repeats(): |
@@ -458,23 +458,13 @@ def get_run(run_id): |
458 | 458 |
|
459 | 459 | try: |
460 | 460 | return _get_cached_run(run_id) |
461 | | - except (OpenMLCacheException): |
462 | | - try: |
463 | | - run_xml = _perform_api_call("run/%d" % run_id) |
464 | | - except (URLError, UnicodeEncodeError) as e: |
465 | | - # TODO logger.debug |
466 | | - print(e) |
467 | | - raise e |
468 | 461 |
|
| 462 | + except (OpenMLCacheException): |
| 463 | + run_xml = _perform_api_call("run/%d" % run_id) |
469 | 464 | with io.open(run_file, "w", encoding='utf8') as fh: |
470 | 465 | fh.write(run_xml) |
471 | 466 |
|
472 | | - try: |
473 | | - run = _create_run_from_xml(run_xml) |
474 | | - except Exception as e: |
475 | | - # TODO logger.debug |
476 | | - print("Run ID", run_id) |
477 | | - raise e |
| 467 | + run = _create_run_from_xml(run_xml) |
478 | 468 |
|
479 | 469 | with io.open(run_file, "w", encoding='utf8') as fh: |
480 | 470 | fh.write(run_xml) |
|
0 commit comments