(exp)
Merge consecutive Removed, Reduced or Transformed nodes.

    .. note:: Removed nodes are returned unchanged.
Merge consecutive Removed, Reduced or Transformed nodes.
Merge consecutive Removed Reduced or Transformed nodes .
def merge_transforms(exp):
    """
    Merge consecutive Removed, Reduced or Transformed nodes.

    .. note:: Removed nodes are returned unchanged.

    """
    if isinstance(exp, (Var, Removed)):
        return exp
    elif isinstance(exp, (Reduced, Sorted, Transformed)):
        prev = merge_transforms(exp.sub)
        if isinstance(prev, (Reduced, Sorted, Transformed)):
            B = exp.var.compute_value
            assert isinstance(B, Lookup)
            A = B.variable.compute_value
            assert isinstance(A, Lookup)

            new_var = DiscreteVariable(
                exp.var.name,
                values=exp.var.values,
                compute_value=merge_lookup(A, B),
                sparse=exp.var.sparse,
            )
            assert isinstance(prev.sub, Var)
            return Transformed(prev.sub, new_var)
        else:
            assert prev is exp.sub
            return exp
    else:
        raise TypeError
def merge_transforms ( exp ) : if isinstance ( exp , ( Var , Removed ) ) : return exp elif isinstance ( exp , ( Reduced , Sorted , Transformed ) ) : prev = merge_transforms ( exp . sub ) if isinstance ( prev , ( Reduced , Sorted , Transformed ) ) : B = exp . var . compute_value assert isinstance ( B , Lookup ) A = B . variable . compute_value assert isinstance ( A , Lookup ) new_var = DiscreteVariable ( exp . var . name , values = exp . var . values , compute_value = merge_lookup ( A , B ) , sparse = exp . var . sparse , ) assert isinstance ( prev . sub , Var ) return Transformed ( prev . sub , new_var ) else : assert prev is exp . sub return exp else : raise TypeError