Skip to content

Commit 65e8758

Browse files
authored
Merge pull request #239 from openml/add/#220
FIX issue #220, sort dictionaries in flows
2 parents 35c60a9 + 2437837 commit 65e8758

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

openml/flows/sklearn_converter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def sklearn_to_flow(o, parent_model=None):
4949
rval = o
5050
elif isinstance(o, dict):
5151
# TODO: explain what type of parameter is here
52+
if not isinstance(o, OrderedDict):
53+
o = OrderedDict([(key, value) for key, value in sorted(o.items())])
54+
5255
rval = OrderedDict()
5356
for key, value in o.items():
5457
if not isinstance(key, six.string_types):
@@ -133,7 +136,7 @@ def flow_to_sklearn(o, **kwargs):
133136
else:
134137
rval = OrderedDict((flow_to_sklearn(key, **kwargs),
135138
flow_to_sklearn(value, **kwargs))
136-
for key, value in o.items())
139+
for key, value in sorted(o.items()))
137140
elif isinstance(o, (list, tuple)):
138141
rval = [flow_to_sklearn(element, **kwargs) for element in o]
139142
if isinstance(o, tuple):

tests/test_flows/test_flow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ def test_sklearn_to_upload_to_flow(self):
209209
y = iris.target
210210

211211
# Test a more complicated flow
212-
ohe = sklearn.preprocessing.OneHotEncoder(categorical_features=[1])
212+
ohe = sklearn.preprocessing.OneHotEncoder(categorical_features=[1],
213+
handle_unknown='ignore')
213214
scaler = sklearn.preprocessing.StandardScaler(with_mean=False)
214215
pca = sklearn.decomposition.TruncatedSVD()
215216
fs = sklearn.feature_selection.SelectPercentile(

0 commit comments

Comments
 (0)