Skip to content

Commit 96db525

Browse files
authored
MAINT remove python2 support (#623)
* MAINT remove python2 support * MAINT reduce the amount of warnings * MAINT PEP8 * MAINT improve style
1 parent 3ed08f0 commit 96db525

34 files changed

Lines changed: 336 additions & 289 deletions

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ env:
1515
- TEST_DIR=/tmp/test_dir/
1616
- MODULE=openml
1717
matrix:
18-
- DISTRIB="conda" PYTHON_VERSION="2.7" SKLEARN_VERSION="0.20.0"
1918
- DISTRIB="conda" PYTHON_VERSION="3.5" SKLEARN_VERSION="0.20.0"
2019
- DISTRIB="conda" PYTHON_VERSION="3.6" SKLEARN_VERSION="0.20.0"
2120
- DISTRIB="conda" PYTHON_VERSION="3.7" SKLEARN_VERSION="0.20.0" RUN_FLAKE8="true" SKIP_TESTS="true"

ci_scripts/flake8_diff.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ echo "Remotes:"
3838
echo '--------------------------------------------------------------------------------'
3939
git remote --verbose
4040

41+
echo "Travis variables:"
42+
echo '--------------------------------------------------------------------------------'
43+
echo "On travis: $TRAVIS"
44+
echo "Current branch: $TRAVIS_BRANCH"
45+
echo "Is a pull request test: $TRAVIS_PULL_REQUEST"
46+
echo "Repository: $TRAVIS_REPO_SLUG"
47+
4148
# Travis does the git clone with a limited depth (50 at the time of
4249
# writing). This may not be enough to find the common ancestor with
4350
# $REMOTE/develop so we unshallow the git checkout
@@ -48,6 +55,14 @@ if [[ -a .git/shallow ]]; then
4855
fi
4956

5057
if [[ "$TRAVIS" == "true" ]]; then
58+
if [[ "$TRAVIS_BRANCH" == "master" ]]
59+
then
60+
# We do not test PEP8 on the master branch (or for the PR test into
61+
# master) as this results in failures which are only shown for the
62+
# pull request to finish a release (development to master) and are
63+
# therefore a pain to fix
64+
exit 0
65+
fi
5166
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]
5267
then
5368
# In main repo, using TRAVIS_COMMIT_RANGE to test the commits
@@ -116,7 +131,7 @@ echo -e '\nRunning flake8 on the diff in the range' "$COMMIT_RANGE" \
116131
echo '--------------------------------------------------------------------------------'
117132
# We need the following command to exit with 0 hence the echo in case
118133
# there is no match
119-
MODIFIED_FILES="$(git diff --name-only $COMMIT_RANGE || echo "no_match")"
134+
MODIFIED_FILES="$(git diff --no-ext-diff --name-only $COMMIT_RANGE || echo "no_match")"
120135

121136
check_files() {
122137
files="$1"
@@ -125,7 +140,7 @@ check_files() {
125140
if [ -n "$files" ]; then
126141
# Conservative approach: diff without context (--unified=0) so that code
127142
# that was not changed does not create failures
128-
git diff --unified=0 $COMMIT_RANGE -- $files | flake8 --ignore E402 --diff --show-source $options
143+
git diff --no-ext-diff --unified=0 $COMMIT_RANGE -- $files | flake8 --ignore E402 --diff --show-source $options
129144
fi
130145
}
131146

@@ -137,4 +152,4 @@ else
137152
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" \
138153
--config ./examples/.flake8
139154
fi
140-
echo -e "No problem detected by flake8\n"
155+
echo -e "No problem detected by flake8\n"

doc/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Example
2222
2323
import openml
2424
from sklearn import preprocessing, tree, pipeline
25-
25+
2626
# Set the OpenML API Key which is required to upload your runs.
2727
# You can get your own API by signing up to OpenML.org.
2828
openml.config.apikey = 'ABC'
29-
29+
3030
# Define a scikit-learn classifier or pipeline
3131
clf = pipeline.Pipeline(
3232
steps=[
@@ -38,7 +38,7 @@ Example
3838
# cross-validation.
3939
task = openml.tasks.get_task(31)
4040
# Run the scikit-learn model on the task (requires an API key).
41-
run = openml.runs.run_model_on_task(task, clf)
41+
run = openml.runs.run_model_on_task(clf, task)
4242
# Publish the experiment on OpenML (optional, requires an API key).
4343
run.publish()
4444
print('View the run online: %s/run/%d' % (openml.config.server, run.run_id))

doc/progress.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Progress
99
Changelog
1010
=========
1111

12+
0.9.0
13+
~~~~~
14+
15+
* ADD #560: OpenML-Python can now handle regression tasks as well.
16+
* MAINT #184: Dropping Python2 support.
17+
1218
0.8.0
1319
~~~~~
1420

openml/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import logging
55
import os
66

7-
from six import StringIO
8-
from six.moves import configparser
9-
from six.moves.urllib_parse import urlparse
7+
from io import StringIO
8+
import configparser
9+
from urllib.parse import urlparse
1010

1111

1212
logger = logging.getLogger(__name__)
@@ -91,7 +91,7 @@ def _parse_config():
9191
for line in fh:
9292
config_file_.write(line)
9393
config_file_.seek(0)
94-
config.readfp(config_file_)
94+
config.read_file(config_file_)
9595
except OSError as e:
9696
logging.info("Error opening file %s: %s", config_file, e.message)
9797
return config

openml/datasets/data_feature.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import six
2-
31
class OpenMLDataFeature(object):
42
"""Data Feature (a.k.a. Attribute) object.
53
@@ -30,11 +28,7 @@ def __init__(self, index, name, data_type, nominal_values,
3028
raise ValueError('number_missing_values is of wrong datatype')
3129

3230
self.index = index
33-
# In case of python version lower than 3, change the default ASCII encoder.
34-
if six.PY2:
35-
self.name = str(name.encode('utf8'))
36-
else:
37-
self.name = str(name)
31+
self.name = str(name)
3832
self.data_type = str(data_type)
3933
self.nominal_values = nominal_values
4034
self.number_missing_values = number_missing_values

openml/datasets/dataset.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import io
33
import logging
44
import os
5+
import pickle
56
from collections import OrderedDict
67

78
import arff
89
import numpy as np
910
import scipy.sparse
1011
import xmltodict
11-
import six
12-
from six.moves import cPickle as pickle
1312
from warnings import warn
1413

1514
import openml._api_calls
@@ -122,7 +121,7 @@ def __init__(self, name, description, format=None,
122121
self.default_target_attribute = default_target_attribute
123122
self.row_id_attribute = row_id_attribute
124123
self.ignore_attributes = None
125-
if isinstance(ignore_attribute, six.string_types):
124+
if isinstance(ignore_attribute, str):
126125
self.ignore_attributes = [ignore_attribute]
127126
elif isinstance(ignore_attribute, list):
128127
self.ignore_attributes = ignore_attribute
@@ -159,10 +158,7 @@ def __init__(self, name, description, format=None,
159158

160159
if data_file is not None:
161160
if self._data_features_supported():
162-
if six.PY2:
163-
self.data_pickle_file = data_file.replace('.arff', '.pkl.py2')
164-
else:
165-
self.data_pickle_file = data_file.replace('.arff', '.pkl.py3')
161+
self.data_pickle_file = data_file.replace('.arff', '.pkl.py3')
166162

167163
if os.path.exists(self.data_pickle_file):
168164
logger.debug("Data pickle file already exists.")
@@ -327,7 +323,7 @@ def get_data(self, target=None,
327323
if not self.row_id_attribute:
328324
pass
329325
else:
330-
if isinstance(self.row_id_attribute, six.string_types):
326+
if isinstance(self.row_id_attribute, str):
331327
to_exclude.append(self.row_id_attribute)
332328
else:
333329
to_exclude.extend(self.row_id_attribute)
@@ -336,7 +332,7 @@ def get_data(self, target=None,
336332
if not self.ignore_attributes:
337333
pass
338334
else:
339-
if isinstance(self.ignore_attributes, six.string_types):
335+
if isinstance(self.ignore_attributes, str):
340336
to_exclude.append(self.ignore_attributes)
341337
else:
342338
to_exclude.extend(self.ignore_attributes)
@@ -354,7 +350,7 @@ def get_data(self, target=None,
354350
if target is None:
355351
rval.append(data)
356352
else:
357-
if isinstance(target, six.string_types):
353+
if isinstance(target, str):
358354
if ',' in target:
359355
target = target.split(',')
360356
else:
@@ -368,7 +364,7 @@ def get_data(self, target=None,
368364
)
369365
target_categorical = [
370366
cat for cat, column in
371-
six.moves.zip(categorical, attribute_names)
367+
zip(categorical, attribute_names)
372368
if column in target
373369
]
374370
target_dtype = int if target_categorical[0] else float
@@ -475,7 +471,7 @@ def get_features_by_type(self, data_type, exclude=None,
475471
if not isinstance(self.ignore_attributes, list):
476472
raise TypeError("ignore_attributes should be a list")
477473
if self.row_id_attribute is not None:
478-
if not isinstance(self.row_id_attribute, six.string_types):
474+
if not isinstance(self.row_id_attribute, str):
479475
raise TypeError("row id attribute should be a str")
480476
if exclude is not None:
481477
if not isinstance(exclude, list):

openml/datasets/functions.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
import io
33
import os
44
import re
5+
import warnings
56

67
import numpy as np
7-
import six
88
import arff
99
import pandas as pd
1010

1111
import xmltodict
1212
from scipy.sparse import coo_matrix
13-
from oslo_concurrency import lockutils
13+
# Currently, importing oslo raises a lot of warning that it will stop working
14+
# under python3.8; remove this once they disappear
15+
with warnings.catch_warnings():
16+
warnings.simplefilter("ignore")
17+
from oslo_concurrency import lockutils
1418
from collections import OrderedDict
15-
from warnings import warn
1619

1720
import openml.utils
1821
import openml._api_calls
@@ -348,7 +351,7 @@ def get_dataset(dataset_id):
348351
except OpenMLServerException as e:
349352
# if there was an exception, check if the user had access to the dataset
350353
if e.code == 112:
351-
six.raise_from(PrivateDatasetError(e.message), None)
354+
raise PrivateDatasetError(e.message) from None
352355
else:
353356
raise e
354357
finally:

openml/flows/flow.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections import OrderedDict
22

3-
import six
43
import xmltodict
54

65
import openml._api_calls
@@ -192,14 +191,15 @@ def _to_dict(self):
192191
meta_info['description'])
193192

194193
for key_, value in param_dict.items():
195-
if key_ is not None and not isinstance(key_, six.string_types):
194+
if key_ is not None and not isinstance(key_, str):
196195
raise ValueError('Parameter name %s cannot be serialized '
197196
'because it is of type %s. Only strings '
198197
'can be serialized.' % (key_, type(key_)))
199-
if value is not None and not isinstance(value, six.string_types):
198+
if value is not None and not isinstance(value, str):
200199
raise ValueError('Parameter value %s cannot be serialized '
201200
'because it is of type %s. Only strings '
202-
'can be serialized.' % (value, type(value)))
201+
'can be serialized.'
202+
% (value, type(value)))
203203

204204
flow_parameters.append(param_dict)
205205

@@ -215,7 +215,7 @@ def _to_dict(self):
215215
for key_ in component_dict:
216216
# We only need to check if the key is a string, because the
217217
# value is a flow. The flow itself is valid by recursion
218-
if key_ is not None and not isinstance(key_, six.string_types):
218+
if key_ is not None and not isinstance(key_, str):
219219
raise ValueError('Parameter name %s cannot be serialized '
220220
'because it is of type %s. Only strings '
221221
'can be serialized.' % (key_, type(key_)))

openml/flows/functions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import dateutil.parser
22

33
import xmltodict
4-
import six
54

65
import openml._api_calls
76
from . import OpenMLFlow
@@ -119,9 +118,9 @@ def flow_exists(name, external_version):
119118
-----
120119
see http://www.openml.org/api_docs/#!/flow/get_flow_exists_name_version
121120
"""
122-
if not (isinstance(name, six.string_types) and len(name) > 0):
121+
if not (isinstance(name, str) and len(name) > 0):
123122
raise ValueError('Argument \'name\' should be a non-empty string')
124-
if not (isinstance(name, six.string_types) and len(external_version) > 0):
123+
if not (isinstance(name, str) and len(external_version) > 0):
125124
raise ValueError('Argument \'version\' should be a non-empty string')
126125

127126
xml_response = openml._api_calls._perform_api_call(

0 commit comments

Comments
 (0)