Skip to content

Commit 200b56c

Browse files
authored
Merge branch 'develop' into improve_error_logging
2 parents 34d5a96 + 32e98a6 commit 200b56c

5 files changed

Lines changed: 25 additions & 10 deletions

File tree

openml/datasets/data_feature.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ class OpenMLDataFeature(object):
1616
"""
1717
LEGAL_DATA_TYPES = ['nominal', 'numeric', 'string', 'date']
1818

19-
def __init__(self, index, name, data_type, nominal_values, number_missing_values):
19+
def __init__(self, index, name, data_type, nominal_values,
20+
number_missing_values):
2021
if type(index) != int:
2122
raise ValueError('Index is of wrong datatype')
2223
if data_type not in self.LEGAL_DATA_TYPES:
23-
raise ValueError('data type should be in %s, found: %s' %(str(self.LEGAL_DATA_TYPES),data_type))
24+
raise ValueError('data type should be in %s, found: %s' %
25+
(str(self.LEGAL_DATA_TYPES), data_type))
2426
if nominal_values is not None and type(nominal_values) != list:
2527
raise ValueError('Nominal_values is of wrong datatype')
2628
if type(number_missing_values) != int:
@@ -33,4 +35,7 @@ def __init__(self, index, name, data_type, nominal_values, number_missing_values
3335
self.number_missing_values = number_missing_values
3436

3537
def __str__(self):
36-
return "[%d - %s (%s)]" %(self.index, self.name, self.data_type)
38+
return "[%d - %s (%s)]" % (self.index, self.name, self.data_type)
39+
40+
def _repr_pretty_(self, pp, cycle):
41+
pp.text(str(self))

openml/datasets/dataset.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,17 @@ def get_features_by_type(self, data_type, exclude=None,
373373
result : list
374374
a list of indices that have the specified data type
375375
'''
376-
assert data_type in OpenMLDataFeature.LEGAL_DATA_TYPES, "Illegal feature type requested"
376+
if data_type not in OpenMLDataFeature.LEGAL_DATA_TYPES:
377+
raise TypeError("Illegal feature type requested")
377378
if self.ignore_attributes is not None:
378-
assert type(self.ignore_attributes) is list, "ignore_attributes should be a list"
379+
if not isinstance(self.ignore_attributes, list):
380+
raise TypeError("ignore_attributes should be a list")
379381
if self.row_id_attribute is not None:
380-
assert type(self.row_id_attribute) is str, "row id attribute should be a str"
382+
if not isinstance(self.row_id_attribute, six.string_types):
383+
raise TypeError("row id attribute should be a str")
381384
if exclude is not None:
382-
assert type(exclude) is list, "Exclude should be a list"
385+
if not isinstance(exclude, list):
386+
raise TypeError("Exclude should be a list")
383387
# assert all(isinstance(elem, str) for elem in exclude), "Exclude should be a list of strings"
384388
to_exclude = []
385389
if exclude is not None:

openml/tasks/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def _list_tasks(api_call):
142142
xml_string = _perform_api_call(api_call)
143143
except OpenMLServerNoResult:
144144
return []
145-
tasks_dict = xmltodict.parse(xml_string, force_list=('oml:task',))
145+
tasks_dict = xmltodict.parse(xml_string, force_list=('oml:task','oml:input'))
146146
# Minimalistic check if the XML is useful
147147
if 'oml:tasks' not in tasks_dict:
148148
raise ValueError('Error in return XML, does not contain "oml:runs": %s'

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ xmltodict
66
nose
77
requests
88
scikit-learn>=0.18
9+
nbconvert
910
nbformat
1011
python-dateutil
11-
oslo.concurrency
12+
oslo.concurrency

tests/test_tasks/test_task_functions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def test__get_estimation_procedure_list(self):
4242
self.assertIsInstance(estimation_procedures[0], dict)
4343
self.assertEqual(estimation_procedures[0]['task_type_id'], 1)
4444

45+
def test_list_clustering_task(self):
46+
# as shown by #383, clustering tasks can give list/dict casting problems
47+
openml.config.server = self.production_server
48+
openml.tasks.list_tasks(task_type_id=5, size=10)
49+
# the expected outcome is that it doesn't crash. No assertions.
50+
4551
def _check_task(self, task):
4652
self.assertEqual(type(task), dict)
4753
self.assertGreaterEqual(len(task), 2)
@@ -127,7 +133,6 @@ def assert_and_raise(*args, **kwargs):
127133
os.path.join(os.getcwd(), "tasks", "1", "tasks.xml")
128134
))
129135

130-
131136
def test_get_task_with_cache(self):
132137
openml.config.set_cache_directory(self.static_cache_dir)
133138
task = openml.tasks.get_task(1)

0 commit comments

Comments
 (0)