def ig_unfold_tree_with_attr(g, sources, mode):
    """Call igraph.Graph.unfold_tree while preserving vertex and edge
    attributes.

    """
    
    g_unfold, g_map = g.unfold_tree(sources, mode=mode)
    
    g_eids = g.get_eids([(g_map[e.source], g_map[e.target]) for e in g_unfold.es])
    for attr in g.edge_attributes():
        g_unfold.es[attr] = g.es[g_eids][attr]
        
    for attr in g.vertex_attributes():
        g_unfold.vs[attr] = g.vs[g_map][attr]
                                        
    return g_unfold