def reindex_expr(expr, index_map):
    """Changes references to key columns to references to value columns in
    index_map.

    Assumes that named attribute references have been converted to integer
    positions.
    """
    for ex in expr.walk():
        assert (not isinstance(ex, AttributeRef)
                or isinstance(ex, UnnamedAttributeRef))
        if isinstance(ex, UnnamedAttributeRef) and ex.position in index_map:
            ex.position = index_map[ex.position]
dataset/ETHPy150Open uwescience/raco/raco/expression/util.py/reindex_expr/original