File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -795,8 +795,8 @@ def pre_order(self, func=(lambda x: x.id)):
795
795
n = self .count
796
796
797
797
curNode = [None ] * (2 * n )
798
- lvisited = np . zeros (( 2 * n ,), dtype = bool )
799
- rvisited = np . zeros (( 2 * n ,), dtype = bool )
798
+ lvisited = set ( )
799
+ rvisited = set ( )
800
800
curNode [0 ] = self
801
801
k = 0
802
802
preorder = []
@@ -807,13 +807,13 @@ def pre_order(self, func=(lambda x: x.id)):
807
807
preorder .append (func (nd ))
808
808
k = k - 1
809
809
else :
810
- if not lvisited [ ndid ] :
810
+ if ndid not in lvisited :
811
811
curNode [k + 1 ] = nd .left
812
- lvisited [ ndid ] = True
812
+ lvisited . add ( ndid )
813
813
k = k + 1
814
- elif not rvisited [ ndid ] :
814
+ elif ndid not in rvisited :
815
815
curNode [k + 1 ] = nd .right
816
- rvisited [ ndid ] = True
816
+ rvisited . add ( ndid )
817
817
k = k + 1
818
818
# If we've visited the left and right of this non-leaf
819
819
# node already, go up in the tree.
Original file line number Diff line number Diff line change @@ -813,6 +813,15 @@ def test_leaves_list_iris_average(self):
813
813
node = to_tree (Z )
814
814
self .assertTrue ((node .pre_order () == leaves_list (Z )).all ())
815
815
816
+ def test_iris_subtree_pre_order (self ):
817
+ # Tests that pre_order() works when called on sub-trees.
818
+ X = eo ['iris' ]
819
+ Y = pdist (X )
820
+ Z = linkage (X , 'single' )
821
+ node = to_tree (Z )
822
+ self .assertTrue (node .pre_order () == (node .get_left ().pre_order ()
823
+ + node .get_right ().pre_order ()))
824
+
816
825
817
826
class TestCorrespond (TestCase ):
818
827
def test_correspond_empty (self ):
You can’t perform that action at this time.
0 commit comments