|
56 | 56 |
|
57 | 57 | from bigml.api import FINISHED |
58 | 58 | from bigml.util import invert_dictionary, slugify, split |
59 | | - |
| 59 | +from bigml.fields import type_map |
60 | 60 |
|
61 | 61 | # Map operator str to its corresponding function |
62 | 62 | OPERATOR = { |
|
68 | 68 | ">": operator.gt |
69 | 69 | } |
70 | 70 |
|
| 71 | +# Map operator str to its corresponding python operator |
| 72 | +PYTHON_OPERATOR = { |
| 73 | + "<": "<", |
| 74 | + "<=": "<=", |
| 75 | + "=": "==", |
| 76 | + "!=": "!=", |
| 77 | + ">=": ">=", |
| 78 | + ">": ">" |
| 79 | +} |
| 80 | + |
| 81 | + |
71 | 82 | INDENT = ' ' |
72 | 83 |
|
73 | 84 |
|
@@ -226,14 +237,11 @@ def python_body(self, depth=1, cmv=False): |
226 | 237 | body += ("%sif (%s %s %s):\n" % |
227 | 238 | (INDENT * depth, |
228 | 239 | self.fields[child.predicate.field]['slug'], |
229 | | - child.predicate.operator, |
230 | | - child.predicate.value)) |
| 240 | + PYTHON_OPERATOR[child.predicate.operator], |
| 241 | + `child.predicate.value`)) |
231 | 242 | body += child.python_body(depth + 1) |
232 | 243 | 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`) |
237 | 245 | return body |
238 | 246 |
|
239 | 247 | def python(self, out): |
@@ -447,7 +455,7 @@ def extract_common_path(groups): |
447 | 455 | common_path.append(test_common_path) |
448 | 456 | groups[group]['total'][0] = common_path |
449 | 457 | if len(details) > 0: |
450 | | - groups[group]['details'] = sorted(details, |
| 458 | + groups[group]['details'] = sorted(details, |
451 | 459 | key=lambda x: x[1], |
452 | 460 | reverse=True) |
453 | 461 |
|
|
0 commit comments