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

Issue with generating visuals in mapper #252

Closed
wingenium-nagesh opened this issue Jan 29, 2024 · 7 comments · Fixed by #253
Closed

Issue with generating visuals in mapper #252

wingenium-nagesh opened this issue Jan 29, 2024 · 7 comments · Fixed by #253
Labels

Comments

@wingenium-nagesh
Copy link

wingenium-nagesh commented Jan 29, 2024

Describe the bug
During execution of the mapper.visualize() function, it errors out in Visuals.py (line 573 - np.asscalar(object) "Numpy does not support attribute asscalar".

To Reproduce
Steps to reproduce the behavior:

  1. brew install numpy (1.26.3)
  2. Open Visual Studio Code
  3. Follow the instructions in https://kepler-mapper.scikit-tda.org/en/latest/generated/gallery/plot_breast_cancer.html#sphx-glr-generated-gallery-plot-breast-cancer-py
  4. Download the notebook https://kepler-mapper.scikit-tda.org/en/latest/_downloads/a94b1f1598c3cfb97a9077a22fcc2de4/plot_breast_cancer.ipynb
  5. Install kmapper using the following notebook directive
    %pip install --upgrade kmapper
  6. Execute the notebook
  7. It errors out on the below mentioned function:

mapper.visualize(
graph,
path_html="breast-cancer.html",
title="Wisconsin Breast Cancer Dataset",
custom_tooltips=y,
)

Expected behavior
The expectation is that the visualize function should create a visualization map and stores it as an html file with the given filename

Screenshots

Desktop (please complete the following information):

  • OS: MacOS 14.3 (23D56)
  • Browser: Not applicable
  • OS Version: 14.3 (23D56)

Smartphone (please complete the following information):
Not applicable

Additional context
I believe the issue happens because of a bug in the code in Visuals.py on line 573. The code (between lines 569-573) should be replaced as follows:

# Jinja default json serializer can't handle np arrays; provide custom encoding
def my_dumper(obj, **kwargs):
    def np_encoder(object, **kwargs):
        if isinstance(object, np.generic):
            #return np.asscalar(object)  # <-- ERROR and a BUG on line 573
            return object.item()   # <-- The correct code should be this
@catanzaromj
Copy link
Contributor

@wingenium-nagesh Thanks for catching this! If you would like to implement the change yourself, you can fork the repo, make the change on your fork and then open a PR. If you need help with this, let me know.

@linusgun
Copy link

linusgun commented Apr 18, 2024

I got the same error, but luckily I created another venv using Python 3.12.2, numpy 1.26.4 and plotly 5.21.0 and the error disappeared.
The original venv (where I got the error) was Python 3.11.6, numpy 1.26.4 and plotly 5.20.0.
Maybe this can help. Btw I used the same version of kmapper 2.0.1 in both cases

@blue-j
Copy link

blue-j commented Jun 25, 2024

@wingenium-nagesh Thanks for catching this! If you would like to implement the change yourself, you can fork the repo, make the change on your fork and then open a PR. If you need help with this, let me know.

Several people have already submitted this PR.

@wingenium-nagesh
Copy link
Author

@blue-j @catanzaromj : apologies for the delay in responding. I will raise the PR shortly.

@blue-j
Copy link

blue-j commented Jun 25, 2024

you are kind to respond. the PRs are there to approve already. do you have write access? - J

@catanzaromj
Copy link
Contributor

@wingenium-nagesh @blue-j Thank you both for the PRs. The build and deploy process for kepler-mapper is deprecated (notice the tests are only checking with python 3.6 - 3.8 here--and python 3.6 is EOL with no runners available). Give me a week to update the build and release process, and then we can get one of your solutions merged.

wingenium-nagesh pushed a commit to Wingenium/kepler-mapper that referenced this issue Jun 26, 2024
@wingenium-nagesh
Copy link
Author

@catanzaromj @blue-j - thanks. I understand. I've raised the PR [https://github.com/Wingenium/kepler-mapper/tree/bugfix/issue-252-np-asscalar-error]. Thanks!

@catanzaromj catanzaromj linked a pull request Jun 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants