Skip to content

Commit 2975384

Browse files
authored
Merge branch 'develop' into runtests
2 parents 2b2d34c + b4df819 commit 2975384

15 files changed

Lines changed: 61 additions & 116 deletions

File tree

openml/_api_calls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import io
22
import os
33
import requests
4-
import arff
54
import warnings
5+
6+
import arff
67
import xmltodict
78

89
from . import config

openml/config.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""
22
Stores module level information like the API key, cache directory and the server.
33
"""
4-
import os
5-
import sys
64
import logging
5+
import os
6+
7+
from six import StringIO
8+
from six.moves import configparser
9+
710

811
logger = logging.getLogger(__name__)
912
logging.basicConfig(
@@ -15,12 +18,7 @@
1518
cachedir = ""
1619

1720

18-
if sys.version_info[0] < 3:
19-
import ConfigParser as configparser
20-
from StringIO import StringIO
21-
else:
22-
import configparser
23-
from io import StringIO
21+
2422

2523

2624
def _setup():

openml/datasets/dataset.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,11 @@
99

1010
import numpy as np
1111
import scipy.sparse
12+
from six.moves import cPickle as pickle
1213
import xmltodict
1314

1415
from .data_feature import OpenMLDataFeature
1516
from ..exceptions import PyOpenMLError
16-
17-
if sys.version_info[0] >= 3:
18-
import pickle
19-
else:
20-
try:
21-
import cPickle as pickle
22-
except:
23-
import pickle
24-
25-
26-
from ..util import is_string
2717
from .._api_calls import _perform_api_call
2818

2919
logger = logging.getLogger(__name__)
@@ -219,7 +209,7 @@ def get_data(self, target=None, target_dtype=int, include_row_id=False,
219209
if not self.row_id_attribute:
220210
pass
221211
else:
222-
if is_string(self.row_id_attribute):
212+
if isinstance(self.row_id_attribute, six.string_types):
223213
to_exclude.append(self.row_id_attribute)
224214
else:
225215
to_exclude.extend(self.row_id_attribute)
@@ -243,7 +233,7 @@ def get_data(self, target=None, target_dtype=int, include_row_id=False,
243233
if target is None:
244234
rval.append(data)
245235
else:
246-
if is_string(target):
236+
if isinstance(target, six.string_types):
247237
target = [target]
248238
targets = np.array([True if column in target else False
249239
for column in attribute_names])

openml/datasets/functions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from collections import OrderedDict
12
import io
23
import os
34
import re
45
import shutil
5-
from collections import OrderedDict
6+
67
import xmltodict
8+
79
from .dataset import OpenMLDataset
810
from ..exceptions import OpenMLCacheException
911
from .. import config

openml/runs/functions.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
from collections import defaultdict
22
import io
3+
import json
34
import os
4-
import xmltodict
5-
import numpy as np
5+
import sys
6+
import time
67
import warnings
8+
9+
import numpy as np
710
import sklearn
8-
import time
911
import six
10-
import json
12+
import xmltodict
1113

1214
from ..exceptions import PyOpenMLError
1315
from .. import config
14-
1516
from ..flows import sklearn_to_flow, get_flow, flow_exists, _check_n_jobs
1617
from ..setups import setup_exists, initialize_model
17-
1818
from ..exceptions import OpenMLCacheException, OpenMLServerException
19-
from ..util import URLError, version_complies
2019
from .._api_calls import _perform_api_call, _file_id_to_url
2120
from .run import OpenMLRun, _get_version_information
2221
from .trace import OpenMLRunTrace, OpenMLTraceIteration
@@ -26,7 +25,6 @@
2625
# circular imports
2726

2827

29-
3028
def run_task(task, model, avoid_duplicate_runs=True, flow_tags=None, seed=None):
3129
"""Performs a CV run on the dataset of the given task, using the split.
3230
@@ -303,7 +301,9 @@ def _run_task_get_arffcontent(model, task, class_labels):
303301
user_defined_measures = defaultdict(lambda: defaultdict(dict))
304302

305303
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)
307307
# TODO use different iterator to only provide a single iterator (less
308308
# methods, less maintenance, less confusion)
309309
for rep in task.iterate_repeats():
@@ -465,23 +465,13 @@ def get_run(run_id):
465465

466466
try:
467467
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
475468

469+
except (OpenMLCacheException):
470+
run_xml = _perform_api_call("run/%d" % run_id)
476471
with io.open(run_file, "w", encoding='utf8') as fh:
477472
fh.write(run_xml)
478473

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)
485475

486476
with io.open(run_file, "w", encoding='utf8') as fh:
487477
fh.write(run_xml)

openml/setups/functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from collections import OrderedDict
2+
13
import openml
24
import xmltodict
3-
import copy
45

5-
from collections import OrderedDict
66
from .setup import OpenMLSetup, OpenMLParameter
77

8+
89
def setup_exists(downloaded_flow, sklearn_model):
910
'''
1011
Checks whether a flow / hyperparameter configuration already exists on the server

openml/tasks/functions.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from collections import OrderedDict
12
import io
2-
import os
33
import re
4-
from collections import OrderedDict
4+
import os
5+
56
import xmltodict
67

7-
from ..util import URLError
88
from ..exceptions import OpenMLCacheException
99
from .. import datasets
1010
from .task import OpenMLTask, _create_task_cache_dir
@@ -103,12 +103,11 @@ def list_tasks(task_type_id=None, offset=None, size=None, tag=None):
103103
104104
Returns
105105
-------
106-
list
107-
A list of all tasks having the given task_type_id and the give tag.
108-
Every task is represented by a dictionary containing the following
109-
information: task id, dataset id, task_type and status. If qualities
110-
are calculated for the associated dataset, some of these are also
111-
returned.
106+
dict
107+
All tasks having the given task_type_id and the give tag. Every task is
108+
represented by a dictionary containing the following information:
109+
task id, dataset id, task_type and status. If qualities are calculated
110+
for the associated dataset, some of these are also returned.
112111
"""
113112
api_call = "task/list"
114113
if task_type_id is not None:
@@ -146,7 +145,7 @@ def _list_tasks(api_call):
146145
% str(tasks_dict))
147146

148147
try:
149-
tasks = dict();
148+
tasks = dict()
150149
procs = _get_estimation_procedure_list()
151150
proc_dict = dict((x['id'], x) for x in procs)
152151
for task_ in tasks_dict['oml:tasks']['oml:task']:
@@ -199,13 +198,9 @@ def get_task(task_id):
199198
try:
200199
with io.open(xml_file, encoding='utf8') as fh:
201200
task = _create_task_from_xml(fh.read())
202-
except (OSError, IOError):
203201

204-
try:
205-
task_xml = _perform_api_call("task/%d" % task_id)
206-
except (URLError, UnicodeEncodeError) as e:
207-
print(e)
208-
raise e
202+
except (OSError, IOError):
203+
task_xml = _perform_api_call("task/%d" % task_id)
209204

210205
with io.open(xml_file, "w", encoding='utf8') as fh:
211206
fh.write(task_xml)

openml/tasks/split.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
from collections import namedtuple, OrderedDict
22
import os
33
import sys
4+
45
import numpy as np
56
import scipy.io.arff
6-
7-
if sys.version_info[0] > 3:
8-
import pickle
9-
else:
10-
try:
11-
import cPickle as pickle
12-
except:
13-
import pickle
7+
from six.moves import cPickle as pickle
148

159

1610
Split = namedtuple("Split", ["train", "test"])

openml/tasks/task.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from .. import config
55
from .. import datasets
6-
from ..util import URLError
76
from .split import OpenMLSplit
87
from .._api_calls import _read_url
98

@@ -70,11 +69,7 @@ def _download_split(self, cache_file):
7069
pass
7170
except (OSError, IOError):
7271
split_url = self.estimation_procedure["data_splits_url"]
73-
try:
74-
split_arff = _read_url(split_url)
75-
except (URLError, UnicodeEncodeError) as e:
76-
print(e, split_url)
77-
raise e
72+
split_arff = _read_url(split_url)
7873

7974
with io.open(cache_file, "w", encoding='utf8') as fh:
8075
fh.write(split_arff)

openml/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import hashlib
22
import inspect
33
import os
4-
import time
54
import shutil
5+
import time
66
import unittest
7+
78
import openml
89

910

0 commit comments

Comments
 (0)