Skip to content

Hierarchical clustering works under Python2.7 but fails under 3.5 #28

Closed

Description

@tim-littlefair

First, thanks for providing this library, it provided a very easy way to add a geographical clustering feature to a project I am working on (not presently in an open repository, but I am happy to send you and invite to view if it is of interest).

I recently returned to the body of code after a time and was trying to upgrade it from Python2.7 to Python3.5, and found that the HierarchicalCluster class throws an exception under 3.5 on data it processes flawlessly under 2.7.

I reduced the problem to a minimal test case, which follows at the end of this description.
I added some extra logging, and proved to my own satisfaction that the exception is thrown from logic around lines 5 to 25 of linkage.py which appear to relate to caching distance function results. Under 2.7 the a and b parameters in this passage appear to be clusters, whereas under 3.5 they appear to be the key strings.

This was tested under 1.4.1, originally with the .whl file from PyPi, but also with the source unpacked to a directory alongside my code.

Test case follows:

from cluster import HierarchicalClustering
import logging

points1D = {
'p4' : 5,
'p2' : 6,
'p7' : 10,
'p9' : 120,
'p10' : 121,
'p11' : 119,
}

logging.basicConfig(level=logging.DEBUG)

distance_func = lambda a,b : abs(points1D[a]-points1D[b])
cl = HierarchicalClustering(points1D.keys(), distance_func)
clusters = cl.getlevel(20)

print(clusters)

Activity

  1. tim-littlefair commented on Mar 7, 2018

    @tim-littlefair
    ContributorAuthor

    I meant to add, that if I were able to work out what is going on and propose a fix I would issue a pull request.
    I may try again at some time in the future, but right now it's half-past midnight and I have my day job to go to tomorrow.

    The testing is being done on current macOS (not that I would expect that to make a difference).

  2. added a commit that references this issue on May 13, 2018
    1448a25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions