Skip to content

Commit 5e65a47

Browse files
committed
remove file util.py
1 parent af39763 commit 5e65a47

9 files changed

Lines changed: 36 additions & 77 deletions

File tree

openml/datasets/dataset.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import pickle
2424

2525

26-
from ..util import is_string
2726
from .._api_calls import _perform_api_call
2827

2928
logger = logging.getLogger(__name__)
@@ -219,7 +218,7 @@ def get_data(self, target=None, target_dtype=int, include_row_id=False,
219218
if not self.row_id_attribute:
220219
pass
221220
else:
222-
if is_string(self.row_id_attribute):
221+
if isinstance(self.row_id_attribute, six.string_types):
223222
to_exclude.append(self.row_id_attribute)
224223
else:
225224
to_exclude.extend(self.row_id_attribute)
@@ -243,7 +242,7 @@ def get_data(self, target=None, target_dtype=int, include_row_id=False,
243242
if target is None:
244243
rval.append(data)
245244
else:
246-
if is_string(target):
245+
if isinstance(target, six.string_types):
247246
target = [target]
248247
targets = np.array([True if column in target else False
249248
for column in attribute_names])

openml/runs/functions.py

Lines changed: 9 additions & 16 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
@@ -296,7 +294,7 @@ def _run_task_get_arffcontent(model, task, class_labels):
296294
user_defined_measures = defaultdict(lambda: defaultdict(dict))
297295

298296
rep_no = 0
299-
can_measure_runtime = version_complies(3, 3) and _check_n_jobs(model)
297+
can_measure_runtime = sys.version_info[:2] >= (3, 3) and _check_n_jobs(model)
300298
# TODO use different iterator to only provide a single iterator (less
301299
# methods, less maintenance, less confusion)
302300
for rep in task.iterate_repeats():
@@ -447,14 +445,9 @@ def get_run(run_id):
447445

448446
try:
449447
return _get_cached_run(run_id)
450-
except (OpenMLCacheException):
451-
try:
452-
run_xml = _perform_api_call("run/%d" % run_id)
453-
except (URLError, UnicodeEncodeError) as e:
454-
# TODO logger.debug
455-
print(e)
456-
raise e
457448

449+
except (OpenMLCacheException):
450+
run_xml = _perform_api_call("run/%d" % run_id)
458451
with io.open(run_file, "w", encoding='utf8') as fh:
459452
fh.write(run_xml)
460453

openml/tasks/functions.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections import OrderedDict
55
import xmltodict
66

7-
from ..util import URLError
87
from ..exceptions import OpenMLCacheException
98
from .. import datasets
109
from .task import OpenMLTask, _create_task_cache_dir
@@ -103,12 +102,11 @@ def list_tasks(task_type_id=None, offset=None, size=None, tag=None):
103102
104103
Returns
105104
-------
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.
105+
dict
106+
All tasks having the given task_type_id and the give tag. Every task is
107+
represented by a dictionary containing the following information:
108+
task id, dataset id, task_type and status. If qualities are calculated
109+
for the associated dataset, some of these are also returned.
112110
"""
113111
api_call = "task/list"
114112
if task_type_id is not None:
@@ -146,7 +144,7 @@ def _list_tasks(api_call):
146144
% str(tasks_dict))
147145

148146
try:
149-
tasks = dict();
147+
tasks = dict()
150148
procs = _get_estimation_procedure_list()
151149
proc_dict = dict((x['id'], x) for x in procs)
152150
for task_ in tasks_dict['oml:tasks']['oml:task']:
@@ -199,13 +197,9 @@ def get_task(task_id):
199197
try:
200198
with io.open(xml_file, encoding='utf8') as fh:
201199
task = _create_task_from_xml(fh.read())
202-
except (OSError, IOError):
203200

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

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

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/util.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/test_datasets/test_dataset.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import os
44

55
import numpy as np
6+
import six
67

78
from openml import OpenMLDataset
8-
from openml.util import is_string
99

1010

1111
class OpenMLDatasetTest(unittest.TestCase):
@@ -64,7 +64,8 @@ def test_get_data(self):
6464
rval, attribute_names = self.dataset.get_data(
6565
return_attribute_names=True)
6666
self.assertEqual(len(attribute_names), 39)
67-
self.assertTrue(all([is_string(att) for att in attribute_names]))
67+
self.assertTrue(all([isinstance(att, six.string_types)
68+
for att in attribute_names]))
6869

6970
def test_get_sparse_dataset(self):
7071
rval = self.sparse_dataset.get_data()
@@ -80,7 +81,8 @@ def test_get_sparse_dataset(self):
8081
return_attribute_names=True)
8182
self.assertIsInstance(rval, np.ndarray)
8283
self.assertEqual(len(attribute_names), 20001)
83-
self.assertTrue(all([is_string(att) for att in attribute_names]))
84+
self.assertTrue(all([isinstance(att, six.string_types)
85+
for att in attribute_names]))
8486

8587
def test_get_data_with_target(self):
8688
X, y = self.dataset.get_data(target="class")

tests/test_datasets/test_dataset_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
else:
99
import mock
1010

11+
import six
1112
import scipy.sparse
1213

1314
import openml
1415
from openml import OpenMLDataset
1516
from openml.exceptions import OpenMLCacheException, PyOpenMLError
16-
from openml.util import is_string
1717
from openml.testing import TestBase
1818

1919
from openml.datasets.functions import (_get_cached_dataset,
@@ -98,7 +98,7 @@ def _check_dataset(self, dataset):
9898
self.assertIn('did', dataset)
9999
self.assertIsInstance(dataset['did'], int)
100100
self.assertIn('status', dataset)
101-
self.assertTrue(is_string(dataset['status']))
101+
self.assertIsInstance(dataset['status'], six.string_types)
102102
self.assertIn(dataset['status'], ['in_preparation', 'active',
103103
'deactivated'])
104104

tests/test_flows/test_flow_functions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
import copy
33
import unittest
44

5+
import six
6+
57
import openml
6-
from openml.util import is_string
78

89

910
class TestFlowFunctions(unittest.TestCase):
1011
def _check_flow(self, flow):
1112
self.assertEqual(type(flow), dict)
1213
self.assertEqual(len(flow), 6)
1314
self.assertIsInstance(flow['id'], int)
14-
self.assertTrue(is_string(flow['name']))
15-
self.assertTrue(is_string(flow['full_name']))
16-
self.assertTrue(is_string(flow['version']))
15+
self.assertIsInstance(flow['name'], six.string_types)
16+
self.assertIsInstance(flow['full_name'], six.string_types)
17+
self.assertIsInstance(flow['version'], six.string_types)
1718
# There are some runs on openml.org that can have an empty external
1819
# version
19-
self.assertTrue(is_string(flow['external_version']) or
20+
self.assertTrue(isinstance(flow['external_version'], six.string_types) or
2021
flow['external_version'] is None)
2122

2223
def test_list_flows(self):

tests/test_tasks/test_task_functions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22
import sys
33

4+
import six
5+
46
if sys.version_info[0] >= 3:
57
from unittest import mock
68
else:
79
import mock
810

9-
from openml.util import is_string
1011
from openml.testing import TestBase
1112
from openml import OpenMLSplit, OpenMLTask
1213
from openml.exceptions import OpenMLCacheException
@@ -45,7 +46,7 @@ def _check_task(self, task):
4546
self.assertIn('did', task)
4647
self.assertIsInstance(task['did'], int)
4748
self.assertIn('status', task)
48-
self.assertTrue(is_string(task['status']))
49+
self.assertIsInstance(task['status'], six.string_types)
4950
self.assertIn(task['status'],
5051
['in_preparation', 'active', 'deactivated'])
5152

0 commit comments

Comments
 (0)