Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5f3b33f

Browse filesBrowse files
committed
added get study functionality
1 parent cb9dcfa commit 5f3b33f
Copy full SHA for 5f3b33f

File tree

Expand file treeCollapse file tree

3 files changed

+59
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+59
-5
lines changed
Open diff view settings
Collapse file

‎openml/study/functions.py‎

Copy file name to clipboard
+43-4Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
11
import xmltodict
22

3+
from openml.study import OpenMLStudy
34
from .._api_calls import _perform_api_call
45

6+
def _multitag_to_list(result_dict, tag):
7+
if isinstance(result_dict[tag], list):
8+
return result_dict[tag]
9+
elif isinstance(result_dict[tag], dict):
10+
return [result_dict[tag]]
11+
else:
12+
raise TypeError()
13+
14+
515
def get_study(study_id):
6-
xml_string = _perform_api_call("study/" % (study_id))
7-
result_dict = xmltodict.parse(xml_string)
8-
9-
pass
16+
xml_string = _perform_api_call("study/%d" %(study_id))
17+
result_dict = xmltodict.parse(xml_string)['oml:study']
18+
id = int(result_dict['oml:id'])
19+
name = result_dict['oml:name']
20+
description = result_dict['oml:description']
21+
creation_date = result_dict['oml:creation_date']
22+
creator = result_dict['oml:creator']
23+
tags = []
24+
for tag in _multitag_to_list(result_dict, 'oml:tag'):
25+
tags.append({'name': tag['oml:name'],
26+
'window_start': tag['oml:window_start'],
27+
'write_access': tag['oml:write_access']})
28+
29+
datasets = None
30+
tasks = None
31+
flows = None
32+
setups = None
33+
34+
if 'oml:data' in result_dict:
35+
datasets = [int(x) for x in result_dict['oml:data']['oml:data_id']]
36+
37+
if 'oml:tasks' in result_dict:
38+
tasks = [int(x) for x in result_dict['oml:tasks']['oml:task_id']]
39+
40+
if 'oml:flows' in result_dict:
41+
flows = [int(x) for x in result_dict['oml:flows']['oml:flow_id']]
42+
43+
if 'oml:setups' in result_dict:
44+
setups = [int(x) for x in result_dict['oml:setups']['oml:setup_id']]
45+
46+
study = OpenMLStudy(id, name, description, creation_date, creator, tags,
47+
datasets, tasks, flows, setups)
48+
return study
Collapse file

‎tests/test_evaluations/test_evaluation_functions.py‎

Copy file name to clipboardExpand all lines: tests/test_evaluations/test_evaluation_functions.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import unittest
21
import openml
32
import openml.evaluations
43
from openml.testing import TestBase
Collapse file
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import openml
2+
import openml.study
3+
from openml.testing import TestBase
4+
5+
class TestStudyFunctions(TestBase):
6+
7+
def test_get_study(self):
8+
openml.config.server = self.production_server
9+
10+
study_id = 34
11+
12+
study = openml.study.get_study(study_id)
13+
self.assertEquals(len(study.data), 105)
14+
self.assertEquals(len(study.tasks), 105)
15+
self.assertEquals(len(study.flows), 27)
16+
self.assertEquals(len(study.setups), 30)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.