def get_ancestors(cur, node, sort=True):
    # TODO: benchmark if vectorize_nodes() or WITH RECURSIVE is faster
    sql = """
        SELECT
          nodes.*
        FROM
          ancestors
        INNER JOIN
          nodes
        ON
          ancestors.ancestor=nodes.id
        WHERE
          ancestors.node=%s;
    """
    cur.execute(sql, (int(node), ))

    if sort:
        make_node = lambda r: NodeData(**r)
        for node in vectorize_nodes(map(make_node, cur)):
            yield node
    else:
        for result in cur:
            yield NodeData(**result)
Return an iterator that yields a ``NodeData`` object of every
dataset/ETHPy150Open conceptsandtraining/libtree/libtree/core/query.py/get_ancestors