clustergrammer2 icon indicating copy to clipboard operation
clustergrammer2 copied to clipboard

KeyError "Y" axis not found on net.cluster with run_clustering=False

Open antoinegaston opened this issue 2 years ago • 0 comments

Describe the bug This bug appears when I try to cluster over a 1D matrix like:

        col_1
row_1    1.2
row_2.   1.5

With run_clustering option at False. A True value leads to the ValueError: The number of observations cannot be determined on an empty distance matrix. which is expected because clustering doesn't make any sense over one columns in my opinion but I feel like a run_clustering at False should not produce any error. The full trace is:

    net.cluster(run_clustering=False, enrichrgram=True)
.venv/lib/python3.7/site-packages/clustergrammer2/clustergrammer_fun/__init__.py:116: in cluster
    min_cluster_size=min_cluster_size)
.venv/lib/python3.7/site-packages/clustergrammer2/clustergrammer_fun/make_clust_fun.py:33: in make_clust
    min_cluster_size=min_cluster_size)
.venv/lib/python3.7/site-packages/clustergrammer2/clustergrammer_fun/calc_clust.py:77: in cluster_row_and_col
    make_viz.viz_json(net, dendro, links)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

net = <clustergrammer2.clustergrammer_fun.Network object at 0x149675bd0>, dendro = False, links = False

    def viz_json(net, dendro=True, links=False):
        """make the dictionary for the clustergram.js visualization"""
        import numpy as np
    
        from . import calc_clust
    
        # linkage information
        net.viz["linkage"] = {}
>       net.viz["linkage"]["row"] = net.dat["node_info"]["row"]["Y"].tolist()
E       KeyError: 'Y'

It seems like the viz_json function doesn't take in account that the Y axis won't be defined in case of a False run_clustering parameter. I wonder what is the expected behaviour for a one row matrix as well and at the corner case a one element matrix.

To Reproduce Steps to reproduce the behavior: With a one column dataframe df run:

net.load_df(df)
net.cluster(run_clustering=False)

Expected behavior Should not raise any error.

Desktop (please complete the following information): macOs monterey 12.4 python 3.7.4, clustergrammer2 0.18.0

antoinegaston avatar Sep 28 '22 08:09 antoinegaston