File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -224,8 +224,9 @@ def conditional_tree_from_paths(paths, minimum_support):
224
224
# Finally, remove the nodes corresponding to the item for which this
225
225
# conditional tree was generated.
226
226
for node in tree .nodes (condition_item ):
227
- node .parent .remove (item )
228
-
227
+ if node .parent is not None : # the node might already be an orphan
228
+ node .parent .remove (node )
229
+
229
230
return tree
230
231
231
232
class FPNode (object ):
@@ -266,6 +267,17 @@ def remove(self, child):
266
267
del self ._children [child .item ]
267
268
child .parent = None
268
269
self ._tree ._removed (child )
270
+ for sub_child in child .children :
271
+ try :
272
+ # Merger case: we already have a child for that item, so
273
+ # add the sub-child's count to our child's count.
274
+ self ._children [sub_child .item ]._count += sub_child .count
275
+ sub_child .parent = None # it's an orphan now
276
+ except KeyError :
277
+ # Turns out we don't actually have a child, so just add
278
+ # the sub-child as our own child.
279
+ self .add (sub_child )
280
+ child ._children = {}
269
281
else :
270
282
raise ValueError ("that node is not a child of this node" )
271
283
except KeyError :
You can’t perform that action at this time.
0 commit comments