Skip to content

Commit c936c31

Browse files
authored
Merge pull request #119 from openml/maint/improve_coverage
MAINT improve coverage: openml.datasets.functions
2 parents 9da3d7b + eb35288 commit c936c31

31 files changed

Lines changed: 132182 additions & 9327 deletions

openml/_api_calls.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .exceptions import OpenMLServerError
88

99

10-
def _perform_api_call(call, data=None, file_dictionary=None,
10+
def _perform_api_call(call, file_dictionary=None,
1111
file_elements=None, add_authentication=True):
1212
"""
1313
Perform an API call at the OpenML server.
@@ -18,11 +18,14 @@ def _read_url(self, url, add_authentication=False, data=None, filePath=None):
1818
----------
1919
call : str
2020
The API call. For example data/list
21-
data : dict (default=None)
22-
Dictionary containing data which will be sent to the OpenML
23-
server via a POST request.
24-
**kwargs
25-
Further arguments which are appended as GET arguments.
21+
file_dictionary : dict
22+
Mapping of {filename: path} of files which should be uploaded to the
23+
server.
24+
file_elements : dict
25+
Mapping of {filename: str} of strings which should be uploaded as
26+
files to the server.
27+
add_authentication : bool
28+
Whether to add authentication (api key) to the request.
2629
2730
Returns
2831
-------
@@ -36,16 +39,16 @@ def _read_url(self, url, add_authentication=False, data=None, filePath=None):
3639
url += "/"
3740
url += call
3841
if file_dictionary is not None or file_elements is not None:
39-
return _read_url_files(url, data=data, file_dictionary=file_dictionary,
42+
return _read_url_files(url, file_dictionary=file_dictionary,
4043
file_elements=file_elements)
41-
return _read_url(url, data=data)
44+
return _read_url(url)
4245

4346

44-
def _read_url_files(url, data=None, file_dictionary=None, file_elements=None):
47+
def _read_url_files(url, file_dictionary=None, file_elements=None):
4548
"""do a post request to url with data None, file content of
4649
file_dictionary and sending file_elements as files"""
47-
if data is None:
48-
data = {}
50+
51+
data = {}
4952
data['api_key'] = config.apikey
5053
if file_elements is None:
5154
file_elements = {}
@@ -78,9 +81,9 @@ def _read_url_files(url, data=None, file_dictionary=None, file_elements=None):
7881
return response.status_code, response.text
7982

8083

81-
def _read_url(url, data=None):
82-
if data is None:
83-
data = {}
84+
def _read_url(url):
85+
86+
data = {}
8487
data['api_key'] = config.apikey
8588

8689
# Using requests.post sets header 'Accept-encoding' automatically to

openml/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _setup():
5151
set_cache_directory(cache_dir, private_dir)
5252

5353

54-
def set_cache_directory(cachedir, privatedir):
54+
def set_cache_directory(cachedir, privatedir=None):
5555
"""Set module-wide cache directory.
5656
5757
Sets the cache directory into which to download datasets, tasks etc.

openml/datasets/dataset.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import gzip
2+
import logging
23
import os
34
import sys
4-
import logging
5+
56
import arff
67

78
import numpy as np
@@ -267,12 +268,17 @@ def publish(self):
267268
return_value : string
268269
xml return from server
269270
"""
270-
data = {'description': self._to_xml()}
271+
272+
file_elements = {'description': self._to_xml()}
273+
file_dictionary = {}
274+
271275
if self.data_file is not None:
272-
return_code, return_value = _perform_api_call(
273-
"/data/", data=data, file_dictionary={'dataset': self.data_file})
274-
else:
275-
return_code, return_value = _perform_api_call("/data/", data=data)
276+
file_dictionary['dataset'] = self.data_file
277+
278+
return_code, return_value = _perform_api_call(
279+
"/data/", file_dictionary=file_dictionary,
280+
file_elements=file_elements)
281+
276282
return return_code, return_value
277283

278284
def _to_xml(self):

0 commit comments

Comments
 (0)