Data type mismatch error #57
Unanswered
AmiParadkar
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Give this a try: import rule_engine
import datetime
company = {
'name': 'Company name',
'establishmentDate': datetime.date(2021, 4, 8)
}
rule = rule_engine.Rule('$today - t"P90D" > establishmentDate')
print('matches: ' + repr(rule.matches(company))) Your original had multiple problems, including:
Hope that helps. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a very simple code,
`import rule_engine
from datetime import datetime
company = {
'name': 'Company name',
"establishmentDate": "2021-04-08"
}
rule = rule_engine.Rule(
'("today()" - "3 months" > establishmentDate)'
)
rule.matches(company)`
but I am getting the following error
Traceback (most recent call last):
File "/Users/Documents/apps/PyCharm/tutorial/test.py", line 9, in
rule = rule_engine.Rule(
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/engine.py", line 578, in init
self.statement = self.parser.parse(text, context)
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/parser.py", line 106, in parse
return result.build()
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/parser.py", line 60, in build
return constructor(*self.args, **self.kwargs)
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/ast.py", line 1041, in build
return cls(context, expression.build()).reduce()
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/parser.py", line 60, in build
return constructor(*self.args, **self.kwargs)
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/ast.py", line 362, in build
return cls(context, type_, left.build(), right.build()).reduce()
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/parser.py", line 60, in build
return constructor(*self.args, **self.kwargs)
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/ast.py", line 362, in build
return cls(context, type_, left.build(), right.build()).reduce()
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/ast.py", line 435, in init
super(SubtractExpression, self).init(*args, **kwargs)
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/ast.py", line 355, in init
self._assert_type_is_compatible(left)
File "/Users/Documents/apps/PyCharm/tutorial/venv/lib/python3.10/site-packages/rule_engine/ast.py", line 369, in _assert_type_is_compatible
raise errors.EvaluationError('data type mismatch')
rule_engine.errors.EvaluationError: data type mismatch
Beta Was this translation helpful? Give feedback.
All reactions