Rule Formatting#
Functions#
simplify_rule#
- iguanas.rule_formatting.simplify_rule(rule: str) str[source]#
Simplify a rule by removing redundant conditions on the same column.
When multiple conditions exist on the same column, keeps only the most restrictive:
For lower bounds (>, >=): keeps the highest threshold, preferring > over >= when equal
For upper bounds (<, <=): keeps the lowest threshold, preferring < over <= when equal
- Parameters:
rule (str) – Rule string with conditions like (X[“col”] > val) & (X[“col”] >= val).
- Returns:
Simplified rule string with redundant conditions removed. Column order is preserved based on first appearance.
- Return type:
str
Examples
>>> simplify_rule('(X["amount"] >= 100.0) & (X["amount"] > 100.0)') '(X["amount"] > 100.0)'
>>> simplify_rule('(X["amount"] < 100.0) & (X["amount"] <= 100.0)') '(X["amount"] < 100.0)'
>>> simplify_rule('(X["a"] >= 50) & (X["b"] < 10) & (X["a"] > 100)') '(X["a"] > 100) & (X["b"] < 10)'