Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
antoinegaston opened this issue Sep 28, 2022 · 0 comments
Open

Comments

@antoinegaston
Copy link

antoinegaston commented Sep 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant