File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change @@ -1218,16 +1218,9 @@ cdef class Tree(object):
1218
1218
ops.ladderize(self , topological, reverse)
1219
1219
1220
1220
def sort_descendants (self , prop = ' name' ):
1221
- """ Sort branches by node names.
1222
-
1223
- After the tree is sorted, if duplicated names are present,
1224
- extra criteria should be added to sort nodes.
1225
- """
1226
- node2content = self .get_cached_content(prop, container_type = list )
1227
-
1228
- for n in self .traverse():
1229
- if not n.is_leaf:
1230
- n.children.sort(key = lambda x : str (sorted (node2content[x])))
1221
+ """ Sort branches by leaf node values (names or any other given prop)."""
1222
+ leaf_values = self .get_cached_content(prop, container_type = list )
1223
+ ops.sort(self , key = lambda node : tuple (sorted (leaf_values[node])))
1231
1224
1232
1225
def get_cached_content (self , prop = None , container_type = set ,
1233
1226
leaves_only = True ):
You can’t perform that action at this time.
0 commit comments