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

modify _Clustergram._scale function #423

Merged
merged 4 commits into from
Nov 21, 2019

Conversation

illumination-k
Copy link
Contributor

@illumination-k illumination-k commented Oct 4, 2019

About

  • a small bug

Description of changes

When using standarize, Clustergram.scale(self, dim), but using self.scale, self.scale(self._data, standarize) and occured error. So, I simply delete self._data.

Before merging

@shammamah-zz
Copy link
Contributor

@illumination-k Could you please post the code that was causing you to get the error (as well as the error itself)?

@illumination-k
Copy link
Contributor Author

This is my code, and only edit Default Clustergram, adding standadrize option.
This editing caused TypeError: _scale() takes 2 positional arguments but 3 were given.

code

import pandas as pd

import dash
import dash_bio as dashbio
import dash_html_components as html
import dash_core_components as dcc


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

df = pd.read_csv(
    'https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/' +
    'clustergram_mtcars.tsv',
    sep='	', skiprows=4
).set_index('model')

columns = list(df.columns.values)
rows = list(df.index)

app.layout = html.Div([
    "Rows to display",
    dcc.Dropdown(
        id='clustergram-input',
        options=[
            {'label': row, 'value': row} for row in list(df.index)
        ],
        value=rows[:10],
        multi=True,
    ),

    html.Div(
        id='my-clustergram'
    )
])


@app.callback(
    dash.dependencies.Output('my-clustergram', 'children'),
    [dash.dependencies.Input('clustergram-input', 'value')]
)
def update_clustergram(rows):
    if len(rows) < 2:
        return "Please select at least two rows to display."

    return dcc.Graph(figure=dashbio.Clustergram(
        data=df.loc[rows].values,
        column_labels=columns,
        row_labels=rows,
        color_threshold={
            'row': 250,
            'col': 700
        },
        hidden_labels='row',
        height=800,
        width=700,
        standardize='row', # ADD THIS!
    ))

if __name__ == '__main__':
    app.run_server(debug=True)

error log

TypeError: _scale() takes 2 positional arguments but 3 were given

Traceback (most recent call last)
File "clustergram_check.py", line 58, in update_clustergram
standardize='row',
File "\Anaconda3\envs\my_project\lib\site-packages\dash_bio\component_factory\_clustergram.py", line 175, in Clustergram
**kwargs
File "\Anaconda3\envs\my_project\lib\site-packages\dash_bio\component_factory\_clustergram.py", line 343, in __init__
self._data = self._scale(self._data, standardize)
TypeError: _scale() takes 2 positional arguments but 3 were given

@mkcor
Copy link
Contributor

mkcor commented Nov 18, 2019

@shammamah Our internal method _scale() takes two arguments:

def _scale(
self,
dim
):

So this fix might not be sufficient, but it's at least necessary.

@shammamah-zz
Copy link
Contributor

@illumination-k Good catch :) Could you please add an entry in the CHANGELOG?

@mkcor
Copy link
Contributor

mkcor commented Nov 21, 2019

@shammamah Do you mind if I sync up, merge, and submit a matching CHANGELOG entry right afterwards? This tiny PR has been open for too long...

@shammamah-zz
Copy link
Contributor

@mkcor Yes, please do! We can also probably release this as a patch version.

@mkcor mkcor merged commit 2b63dea into plotly:master Nov 21, 2019
@mkcor mkcor mentioned this pull request Nov 21, 2019
3 tasks
@mkcor
Copy link
Contributor

mkcor commented Nov 21, 2019

@shammamah Ok, thanks! But we first need #443 to pass...

@illumination-k illumination-k deleted the modify_standrize_function branch April 7, 2022 08:07
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

Successfully merging this pull request may close these issues.

3 participants