Skip to content

Commit 78c41e2

Browse files
committed
Fix '==' operator and categorical values for Python generation
1 parent 7274202 commit 78c41e2

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

bigml/model.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
from bigml.api import FINISHED
5858
from bigml.util import invert_dictionary, slugify, split
59-
59+
from bigml.fields import type_map
6060

6161
# Map operator str to its corresponding function
6262
OPERATOR = {
@@ -68,6 +68,17 @@
6868
">": operator.gt
6969
}
7070

71+
# Map operator str to its corresponding python operator
72+
PYTHON_OPERATOR = {
73+
"<": "<",
74+
"<=": "<=",
75+
"=": "==",
76+
"!=": "!=",
77+
">=": ">=",
78+
">": ">"
79+
}
80+
81+
7182
INDENT = ' '
7283

7384

@@ -226,14 +237,11 @@ def python_body(self, depth=1, cmv=False):
226237
body += ("%sif (%s %s %s):\n" %
227238
(INDENT * depth,
228239
self.fields[child.predicate.field]['slug'],
229-
child.predicate.operator,
230-
child.predicate.value))
240+
PYTHON_OPERATOR[child.predicate.operator],
241+
`child.predicate.value`))
231242
body += child.python_body(depth + 1)
232243
else:
233-
if self.fields[self.objective_field]['optype'] == 'numeric':
234-
body = "%s return %s\n" % (INDENT * depth, self.output)
235-
else:
236-
body = "%s return '%s'\n" % (INDENT * depth, self.output)
244+
body = "%s return %s\n" % (INDENT * depth, `self.output`)
237245
return body
238246

239247
def python(self, out):
@@ -447,7 +455,7 @@ def extract_common_path(groups):
447455
common_path.append(test_common_path)
448456
groups[group]['total'][0] = common_path
449457
if len(details) > 0:
450-
groups[group]['details'] = sorted(details,
458+
groups[group]['details'] = sorted(details,
451459
key=lambda x: x[1],
452460
reverse=True)
453461

0 commit comments

Comments
 (0)