[Scipy-tickets] [SciPy] #1052: KDTree.query_pair() leafnode attribute error

SciPy Trac scipy-tickets@scipy....
Fri Dec 10 16:48:42 CST 2010

#1052: KDTree.query_pair() leafnode attribute error
 Reporter:  dhelfman       |       Owner:  peridot     
     Type:  defect         |      Status:  needs_review
 Priority:  high           |   Milestone:              
Component:  scipy.spatial  |     Version:  devel       
 Keywords:                 |  
Changes (by WeatherGod):

 * cc: ben.v.root@… (added)
  * priority:  normal => high


 I can explain the source of the bug.  The problem is that when the number
 of points is less than the size of a leaf node, then the tree building
 process will create a "leafnode" type, which indicates that it is a tip of
 the tree structure.  Leaves that are split are "innernode" leaf types,
 which have the 'less' and 'greater' methods to recursively evaluate its

 In normal situations, the root node is of type innernode because we are
 usually dealing with many diverse sets of points.  Only if the number of
 points is smaller than some nodesize value, or if all of the points are
 identical will the root node be a leafnode.

 So, in this case, if the points are close enough then the code normally
 proceeds to continue traversing the leaves.  However, if the root node is
 a leafnode, then you can not traverse the leaves.  Putting the checks for
 isinstance(leafnode) first makes a lot of sense and seems to work well for

 In my opinion, this patch should be pushed out.  Note, that there may
 still be similar issues in some of the other functions, as I have not

Ticket URL: <http://projects.scipy.org/scipy/ticket/1052#comment:2>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list