Skip to content

Tutorial plotly.figure_factory create_dendrogram() not working resulting in AttributeError #4495

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

Closed
Snirpsi opened this issue Jan 25, 2024 · 2 comments

Comments

@Snirpsi
Copy link

Snirpsi commented Jan 25, 2024

Hi,
when i run the tutorial from the website https://plotly.com/python/dendrogram/ the program crashes.

I put the code in a test.py file in a complete new venv.

import plotly.figure_factory as ff
import numpy as np
np.random.seed(1)

X = np.random.rand(15, 12) # 15 samples, with 12 dimensions each
fig = ff.create_dendrogram(X)
fig.update_layout(width=800, height=500)
fig.show()

Error:

Traceback (most recent call last):
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/scipy/__init__.py", line 137, in __getattr__
    return globals()[name]
           ~~~~~~~~~^^^^^^
KeyError: 'array'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/snirps/Documents/GitHub/testproject/test.py", line 6, in <module>
    fig = ff.create_dendrogram(X)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/plotly/figure_factory/_dendrogram.py", line 94, in create_dendrogram
    dendrogram = _Dendrogram(
                 ^^^^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/plotly/figure_factory/_dendrogram.py", line 148, in __init__
    (dd_traces, xvals, yvals, ordered_labels, leaves) = self.get_dendrogram_traces(
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/plotly/figure_factory/_dendrogram.py", line 346, in get_dendrogram_traces
    icoord = scp.array(P["icoord"])
             ^^^^^^^^^
  File "/home/snirps/Documents/GitHub/testproject/.venv/lib/python3.11/site-packages/scipy/__init__.py", line 139, in __getattr__
    raise AttributeError(
AttributeError: Module 'scipy' has no attribute 'array'

I have the following packages installed with pip.

pip==23.2
pipdeptree==2.13.2
plotly==5.18.0
├── packaging [required: Any, installed: 23.2]
└── tenacity [required: >=6.2.0, installed: 8.2.3]
scipy==1.12.0
└── numpy [required: >=1.22.4,<1.29.0, installed: 1.26.3]
setuptools==68.1.2

python:

Python 3.11.6

Thanks for your great work.

@Coding-with-Adam
Copy link
Contributor

hi @Snirpsi
Thank you for sharing this. The error appears to be related to scipy==1.12.0.
If you pip install scipy==1.11.4 it will work.

@alexcjohnson
Copy link
Collaborator

Will be fixed by #4487 which we'll include in the next release (hopefully next week)

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

3 participants