Skip to content

Commit c942308

Browse files
authored
Fix/#392 (#430)
* MAINT move from cell executor to exec to test jupyter notebooks * Mock calls to /run/upload/ in notebook unit tests * FIX mock patch target * Change backend
1 parent 3232d0d commit c942308

File tree

15 files changed

+116
-75
lines changed

15 files changed

+116
-75
lines changed

examples/OpenML_Tutorial.ipynb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@
2323
]
2424
},
2525
{
26-
"cell_type": "raw",
27-
"metadata": {},
26+
"cell_type": "markdown",
27+
"metadata": {
28+
"slideshow": {
29+
"slide_type": "slide"
30+
}
31+
},
2832
"source": [
29-
"# Install OpenML (developer version)\n",
30-
"# 'pip install openml' coming up (october 2017) \n",
31-
"pip install git+https://github.com/openml/openml-python.git@develop"
33+
"# Installation\n",
34+
"\n",
35+
"* Up to now: `pip install git+https://github.com/openml/openml-python.git@develop`\n",
36+
"* In the future: `pip install openml`\n",
37+
"* Check out the installation guide: [https://openml.github.io/openml-python/stable/#installation](https://openml.github.io/openml-python/stable/#installation)"
3238
]
3339
},
3440
{
@@ -1547,7 +1553,7 @@
15471553
"name": "python",
15481554
"nbconvert_exporter": "python",
15491555
"pygments_lexer": "ipython3",
1550-
"version": "3.6.1"
1556+
"version": "3.6.2"
15511557
}
15521558
},
15531559
"nbformat": 4,

openml/datasets/dataset.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from .data_feature import OpenMLDataFeature
1515
from ..exceptions import PyOpenMLError
16-
from .._api_calls import _perform_api_call
16+
import openml._api_calls
1717

1818
logger = logging.getLogger(__name__)
1919

@@ -135,7 +135,7 @@ def push_tag(self, tag):
135135
Tag to attach to the dataset.
136136
"""
137137
data = {'data_id': self.dataset_id, 'tag': tag}
138-
_perform_api_call("/data/tag", data=data)
138+
openml._api_calls._perform_api_call("/data/tag", data=data)
139139

140140
def remove_tag(self, tag):
141141
"""Removes a tag from this dataset on the server.
@@ -146,7 +146,7 @@ def remove_tag(self, tag):
146146
Tag to attach to the dataset.
147147
"""
148148
data = {'data_id': self.dataset_id, 'tag': tag}
149-
_perform_api_call("/data/untag", data=data)
149+
openml._api_calls._perform_api_call("/data/untag", data=data)
150150

151151
def __eq__(self, other):
152152
if type(other) != OpenMLDataset:
@@ -432,8 +432,11 @@ def publish(self):
432432
if self.data_file is not None:
433433
file_dictionary['dataset'] = self.data_file
434434

435-
return_value = _perform_api_call("/data/", file_dictionary=file_dictionary,
436-
file_elements=file_elements)
435+
return_value = openml._api_calls._perform_api_call(
436+
"/data/",
437+
file_dictionary=file_dictionary,
438+
file_elements=file_elements,
439+
)
437440

438441
self.dataset_id = int(xmltodict.parse(return_value)['oml:upload_data_set']['oml:id'])
439442
return self

openml/datasets/functions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
import xmltodict
1010

1111
import openml.utils
12+
import openml._api_calls
1213
from .dataset import OpenMLDataset
1314
from ..exceptions import OpenMLCacheException, OpenMLServerNoResult, \
1415
OpenMLHashException
1516
from .. import config
16-
from .._api_calls import _perform_api_call, _read_url
17+
from .._api_calls import _read_url
1718

1819

1920
############################################################################
@@ -206,7 +207,7 @@ def _list_datasets(**kwargs):
206207

207208
def __list_datasets(api_call):
208209

209-
xml_string = _perform_api_call(api_call)
210+
xml_string = openml._api_calls._perform_api_call(api_call)
210211
datasets_dict = xmltodict.parse(xml_string, force_list=('oml:dataset',))
211212

212213
# Minimalistic check if the XML is useful
@@ -357,7 +358,7 @@ def _get_dataset_description(did_cache_dir, dataset_id):
357358
try:
358359
return _get_cached_dataset_description(dataset_id)
359360
except (OpenMLCacheException):
360-
dataset_xml = _perform_api_call("data/%d" % dataset_id)
361+
dataset_xml = openml._api_calls._perform_api_call("data/%d" % dataset_id)
361362

362363
with io.open(description_file, "w", encoding='utf8') as fh:
363364
fh.write(dataset_xml)
@@ -450,7 +451,7 @@ def _get_dataset_features(did_cache_dir, dataset_id):
450451
with io.open(features_file, encoding='utf8') as fh:
451452
features_xml = fh.read()
452453
except (OSError, IOError):
453-
features_xml = _perform_api_call("data/features/%d" % dataset_id)
454+
features_xml = openml._api_calls._perform_api_call("data/features/%d" % dataset_id)
454455

455456
with io.open(features_file, "w", encoding='utf8') as fh:
456457
fh.write(features_xml)
@@ -486,7 +487,7 @@ def _get_dataset_qualities(did_cache_dir, dataset_id):
486487
with io.open(qualities_file, encoding='utf8') as fh:
487488
qualities_xml = fh.read()
488489
except (OSError, IOError):
489-
qualities_xml = _perform_api_call("data/qualities/%d" % dataset_id)
490+
qualities_xml = openml._api_calls._perform_api_call("data/qualities/%d" % dataset_id)
490491

491492
with io.open(qualities_file, "w", encoding='utf8') as fh:
492493
fh.write(qualities_xml)

openml/evaluations/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from openml.exceptions import OpenMLServerNoResult
44
import openml.utils
5-
from .._api_calls import _perform_api_call
5+
import openml._api_calls
66
from ..evaluations import OpenMLEvaluation
77

88

@@ -93,7 +93,7 @@ def _list_evaluations(function, id=None, task=None,
9393

9494
def __list_evaluations(api_call):
9595
"""Helper function to parse API calls which are lists of runs"""
96-
xml_string = _perform_api_call(api_call)
96+
xml_string = openml._api_calls._perform_api_call(api_call)
9797
evals_dict = xmltodict.parse(xml_string, force_list=('oml:evaluation',))
9898
# Minimalistic check if the XML is useful
9999
if 'oml:evaluations' not in evals_dict:
@@ -117,4 +117,4 @@ def __list_evaluations(api_call):
117117
eval_['oml:upload_time'], float(eval_['oml:value']),
118118
array_data)
119119
evals[run_id] = evaluation
120-
return evals
120+
return evals

openml/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def __init__(self, message, code=None, additional=None, url=None):
2525
self.url = url
2626
super(OpenMLServerException, self).__init__(message)
2727

28+
def __str__(self):
29+
return '%s returned code %s: %s' % (
30+
self.url, self.code, self.message,
31+
)
2832

2933
class OpenMLServerNoResult(OpenMLServerException):
3034
"""exception for when the result of the server is empty. """

openml/flows/flow.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import six
44
import xmltodict
55

6-
from .._api_calls import _perform_api_call
6+
import openml._api_calls
77
from ..utils import extract_xml_tags
88

99

@@ -341,7 +341,10 @@ def publish(self):
341341
xml_description = self._to_xml()
342342

343343
file_elements = {'description': xml_description}
344-
return_value = _perform_api_call("flow/", file_elements=file_elements)
344+
return_value = openml._api_calls._perform_api_call(
345+
"flow/",
346+
file_elements=file_elements,
347+
)
345348
flow_id = int(xmltodict.parse(return_value)['oml:upload_flow']['oml:id'])
346349
flow = openml.flows.functions.get_flow(flow_id)
347350
_copy_server_fields(flow, self)
@@ -364,7 +367,7 @@ def push_tag(self, tag):
364367
Tag to attach to the flow.
365368
"""
366369
data = {'flow_id': self.flow_id, 'tag': tag}
367-
_perform_api_call("/flow/tag", data=data)
370+
openml._api_calls._perform_api_call("/flow/tag", data=data)
368371

369372
def remove_tag(self, tag):
370373
"""Removes a tag from this flow on the server.
@@ -375,7 +378,7 @@ def remove_tag(self, tag):
375378
Tag to attach to the flow.
376379
"""
377380
data = {'flow_id': self.flow_id, 'tag': tag}
378-
_perform_api_call("/flow/untag", data=data)
381+
openml._api_calls._perform_api_call("/flow/untag", data=data)
379382

380383

381384
def _copy_server_fields(source_flow, target_flow):

openml/flows/functions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import xmltodict
44
import six
55

6-
from openml._api_calls import _perform_api_call
7-
from openml.exceptions import OpenMLServerNoResult
6+
import openml._api_calls
87
from . import OpenMLFlow
98
import openml.utils
109

@@ -23,7 +22,7 @@ def get_flow(flow_id):
2322
except:
2423
raise ValueError("Flow ID must be an int, got %s." % str(flow_id))
2524

26-
flow_xml = _perform_api_call("flow/%d" % flow_id)
25+
flow_xml = openml._api_calls._perform_api_call("flow/%d" % flow_id)
2726

2827
flow_dict = xmltodict.parse(flow_xml)
2928
flow = OpenMLFlow._from_dict(flow_dict)
@@ -114,9 +113,10 @@ def flow_exists(name, external_version):
114113
if not (isinstance(name, six.string_types) and len(external_version) > 0):
115114
raise ValueError('Argument \'version\' should be a non-empty string')
116115

117-
xml_response = _perform_api_call(
118-
"flow/exists", data={'name': name, 'external_version':
119-
external_version})
116+
xml_response = openml._api_calls._perform_api_call(
117+
"flow/exists",
118+
data={'name': name, 'external_version': external_version},
119+
)
120120

121121
result_dict = xmltodict.parse(xml_response)
122122
flow_id = int(result_dict['oml:flow_exists']['oml:id'])
@@ -128,7 +128,7 @@ def flow_exists(name, external_version):
128128

129129
def __list_flows(api_call):
130130

131-
xml_string = _perform_api_call(api_call)
131+
xml_string = openml._api_calls._perform_api_call(api_call)
132132
flows_dict = xmltodict.parse(xml_string, force_list=('oml:flow',))
133133

134134
# Minimalistic check if the XML is useful

openml/runs/functions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
import openml
1616
import openml.utils
17+
import openml._api_calls
1718
from ..exceptions import PyOpenMLError, OpenMLServerNoResult
1819
from .. import config
1920
from ..flows import sklearn_to_flow, get_flow, flow_exists, _check_n_jobs, \
2021
_copy_server_fields
2122
from ..setups import setup_exists, initialize_model
2223
from ..exceptions import OpenMLCacheException, OpenMLServerException
23-
from .._api_calls import _perform_api_call
2424
from .run import OpenMLRun, _get_version_information
2525
from .trace import OpenMLRunTrace, OpenMLTraceIteration
2626

@@ -150,7 +150,7 @@ def get_run_trace(run_id):
150150
openml.runs.OpenMLTrace
151151
"""
152152

153-
trace_xml = _perform_api_call('run/trace/%d' % run_id)
153+
trace_xml = openml._api_calls._perform_api_call('run/trace/%d' % run_id)
154154
run_trace = _create_trace_from_description(trace_xml)
155155
return run_trace
156156

@@ -653,7 +653,7 @@ def get_run(run_id):
653653
return _get_cached_run(run_id)
654654

655655
except (OpenMLCacheException):
656-
run_xml = _perform_api_call("run/%d" % run_id)
656+
run_xml = openml._api_calls._perform_api_call("run/%d" % run_id)
657657
with io.open(run_file, "w", encoding='utf8') as fh:
658658
fh.write(run_xml)
659659

@@ -992,7 +992,7 @@ def _list_runs(id=None, task=None, setup=None,
992992

993993
def __list_runs(api_call):
994994
"""Helper function to parse API calls which are lists of runs"""
995-
xml_string = _perform_api_call(api_call)
995+
xml_string = openml._api_calls._perform_api_call(api_call)
996996
runs_dict = xmltodict.parse(xml_string, force_list=('oml:run',))
997997
# Minimalistic check if the XML is useful
998998
if 'oml:runs' not in runs_dict:
@@ -1022,4 +1022,4 @@ def __list_runs(api_call):
10221022

10231023
runs[run_id] = run
10241024

1025-
return runs
1025+
return runs

openml/runs/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import xmltodict
99

1010
import openml
11+
import openml._api_calls
1112
from ..tasks import get_task
12-
from .._api_calls import _perform_api_call, _file_id_to_url
13+
from .._api_calls import _file_id_to_url
1314
from ..exceptions import PyOpenMLError
1415

1516

@@ -234,7 +235,7 @@ def publish(self):
234235
trace_arff = arff.dumps(self._generate_trace_arff_dict())
235236
file_elements['trace'] = ("trace.arff", trace_arff)
236237

237-
return_value = _perform_api_call("/run/", file_elements=file_elements)
238+
return_value = openml._api_calls._perform_api_call("/run/", file_elements=file_elements)
238239
run_id = int(xmltodict.parse(return_value)['oml:upload_run']['oml:run_id'])
239240
self.run_id = run_id
240241
return self
@@ -370,7 +371,7 @@ def push_tag(self, tag):
370371
Tag to attach to the run.
371372
"""
372373
data = {'run_id': self.run_id, 'tag': tag}
373-
_perform_api_call("/run/tag", data=data)
374+
openml._api_calls._perform_api_call("/run/tag", data=data)
374375

375376
def remove_tag(self, tag):
376377
"""Removes a tag from this run on the server.
@@ -381,7 +382,7 @@ def remove_tag(self, tag):
381382
Tag to attach to the run.
382383
"""
383384
data = {'run_id': self.run_id, 'tag': tag}
384-
_perform_api_call("/run/untag", data=data)
385+
openml._api_calls._perform_api_call("/run/untag", data=data)
385386

386387

387388
################################################################################

openml/study/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import xmltodict
22

33
from openml.study import OpenMLStudy
4-
from .._api_calls import _perform_api_call
4+
import openml._api_calls
55

66

77
def _multitag_to_list(result_dict, tag):
@@ -22,7 +22,7 @@ def get_study(study_id, type=None):
2222
call_suffix = "study/%s" %str(study_id)
2323
if type is not None:
2424
call_suffix += "/" + type
25-
xml_string = _perform_api_call(call_suffix)
25+
xml_string = openml._api_calls._perform_api_call(call_suffix)
2626
result_dict = xmltodict.parse(xml_string)['oml:study']
2727
id = int(result_dict['oml:id'])
2828
name = result_dict['oml:name']
@@ -56,4 +56,4 @@ def get_study(study_id, type=None):
5656

5757
study = OpenMLStudy(id, name, description, creation_date, creator, tags,
5858
datasets, tasks, flows, setups)
59-
return study
59+
return study

0 commit comments

Comments
 (0)