Skip to content

Commit 895332b

Browse files
committed
upload methods and their tests.
1 parent 86c7bc0 commit 895332b

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

openml/apiconnector.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,3 +933,84 @@ def _read_url(self, url, add_authentication=False, data=None):
933933
string.write(chunk)
934934

935935
return return_code, string.getvalue()
936+
937+
def upload_dataset(self, dataset, description):
938+
try:
939+
data = {'dataset': dataset, 'description': description}
940+
return_code, dataset_xml = self._perform_api_call("openml.data.upload",data=data)
941+
942+
except URLError as e:
943+
# TODO logger.debug
944+
print(e)
945+
raise e
946+
return return_code, dataset_xml
947+
948+
def upload_dataset(self, description):
949+
try:
950+
data = {'description': description}
951+
return_code, dataset_xml = self._perform_api_call("openml.data.upload",data=data)
952+
953+
except URLError as e:
954+
# TODO logger.debug
955+
print(e)
956+
raise e
957+
return return_code, dataset_xml
958+
959+
def upload_dataset_features(self, description):
960+
try:
961+
data = {'description': description}
962+
return_code, dataset_xml = self._perform_api_call("openml.data.features.upload", data=data)
963+
964+
except URLError as e:
965+
# TODO logger.debug
966+
print(e)
967+
raise e
968+
return return_code, dataset_xml
969+
970+
def upload_dataset_qualities(self, description):
971+
try:
972+
data = {'description': description}
973+
return_code, dataset_xml = self._perform_api_call("openml.data.qualities.upload", data=data)
974+
975+
except URLError as e:
976+
# TODO logger.debug
977+
print(e)
978+
raise e
979+
return return_code, dataset_xml
980+
981+
def upload_implementation(self, description, binary, source):
982+
try:
983+
data = {'description': description, 'binary': binary, 'source': source}
984+
return_code, dataset_xml = self._perform_api_call("openml.implementation.upload", data=data)
985+
986+
except URLError as e:
987+
# TODO logger.debug
988+
print(e)
989+
raise e
990+
return return_code, dataset_xml
991+
992+
def upload_run(self, description, files):
993+
try:
994+
data ={'description': description}
995+
for key, value in files:
996+
data[key] = value
997+
998+
return_code, dataset_xml = self._perform_api_call("openml.run.upload", data=data)
999+
1000+
except URLError as e:
1001+
# TODO logger.debug
1002+
print(e)
1003+
raise e
1004+
return return_code, dataset_xml
1005+
1006+
def upload_file(self, file):
1007+
try:
1008+
data ={'file': file}
1009+
return_code, dataset_xml = self._perform_api_call("openml.file.upload", data=data)
1010+
1011+
except URLError as e:
1012+
# TODO logger.debug
1013+
print(e)
1014+
raise e
1015+
return return_code, dataset_xml
1016+

tests/test_apiconnector.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,55 @@ def test_download_split(self):
239239
self.assertTrue(os.path.exists(
240240
os.path.join(os.getcwd(), "tasks", "1", "datasplits.arff")))
241241

242+
def test_upload_dataset(self):
243+
244+
dataset = """@relation accelerometer
245+
246+
@attribute id {?}
247+
@attribute bag relational
248+
@attribute y numeric
249+
@attribute x numeric
250+
@attribute z numeric
251+
@end bag
252+
253+
@attribute class {A,B,C,?}
254+
255+
@data
256+
?,"3.18163375854,-1.96720916748,9.26677963257\n3.52741470337,-2.7294241333,9.70147567749\n
257+
4.42030792236,-0.964743804932,6.52074005127\n
258+
4.59963500977,-2.74214767456,8.6741619873\n5.19749176025,-1.80330001831,7.57110580444\n","?"
259+
"""
260+
description = """ <oml:data_set_description xmlns:oml="http://openml.org/openml">
261+
<oml:name>anneal</oml:name>
262+
<oml:version>1</oml:version>
263+
<oml:description>test</oml:description>
264+
<oml:format>ARFF</oml:format>
265+
<oml:upload_date>2014-04-06 23:19:24</oml:upload_date>
266+
<oml:licence>Public</oml:licence>
267+
<oml:url></oml:url>
268+
<oml:default_target_attribute>class</oml:default_target_attribute>
269+
<oml:md5_checksum></oml:md5_checksum>
270+
</oml:data_set_description>
271+
"""
272+
return_code, dataset_xml = self.connector.upload_dataset(dataset, description)
273+
self.assertEqual(return_code, 200)
274+
275+
def test_upload_dataset_features(self):
276+
raise Exception()
277+
278+
def test_upload_dataset_qualities(self):
279+
280+
description = """ <oml:data_qualities xmlns:oml="http://openml.org/openml">
281+
<oml:did>1</oml:did>
282+
<oml:quality>
283+
<oml:name>NumberOfInstances</oml:name>
284+
<oml:value>898</oml:value>
285+
</oml:quality>
286+
</oml:data_qualities>
287+
"""
288+
return_code, dataset_xml = self.connector.upload_dataset_qualities(description)
289+
self.assertEqual(return_code, 200)
290+
291+
292+
242293

0 commit comments

Comments
 (0)