Skip to content

markov_cluster.modularity errors when 1st arg is an np.ndarray #26

@Fish-Soup

Description

@Fish-Soup
result = mc.run_mcl(score, **kwargs)
clusters = mc.get_clusters(result) 
modularity = mc.modularity(matrix=result, clusters=clusters)

as score is a np.ndarray (np.matrix is depreciated and data is not sparse) result is also a ndarray. This causes mc.modularity to crash on the function call convert_to_adjacency_matrix().

I found a quick fix which was to

modularity = mc.modularity(matrix=csr_matrix(result), clusters=clusters)

however in cases where some of the data doesnt belong to any clusters, this crashes.
The code functions correctly if
modularity = mc.modularity(matrix=np.matrix(result), clusters=clusters)
however np.matrix is depreciated.

the fix is fairly trivial

 if isspmatrix(matrix):
            col = find(matrix[:,i])[2]
        else:
            col = matrix[:,i].T.tolist()[0]

becomes

if isspmatrix(matrix):
    col = find(matrix[:, i])[2]
elif isinstance(matrix, np.ndarray):
    col =  matrix[:, i].T.tolist()
else:
    col = matrix[:, i].T.tolist()[0]

Could raise a PR but its only 2 lines of code, not sure whats easier.

Many thanks

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