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

Remove numpy dependency for Infogram #7141

Closed
exalate-issue-sync bot opened this issue May 11, 2023 · 5 comments
Closed

Remove numpy dependency for Infogram #7141

exalate-issue-sync bot opened this issue May 11, 2023 · 5 comments
Assignees

Comments

@exalate-issue-sync
Copy link

We should not be importing numpy by default. It's a dependency for the Infogram plot() method in Python, but we need to keep it isolated there.

Remove this line: [https://github.com/h2oai/h2o-3/blob/master/h2o-bindings/bin/custom/python/gen_infogram.py#L241|https://github.com/h2oai/h2o-3/blob/master/h2o-bindings/bin/custom/python/gen_infogram.py#L241]

Even though numpy is a dependency of matplotlib, we should still directly import it somewhere so that the plot() method can use it: [https://github.com/h2oai/h2o-3/blob/master/h2o-bindings/bin/custom/python/gen_infogram.py#L76|https://github.com/h2oai/h2o-3/blob/master/h2o-bindings/bin/custom/python/gen_infogram.py#L76]

Maybe we just make a {{get_numpy}} function similar to what I did for {{get_pollycollection}}? [https://github.com/h2oai/h2o-3/blob/046a0a2438b01926eca936d278cf5b9569200589/h2o-py/h2o/plot/init.py#L2|https://github.com/h2oai/h2o-3/blob/046a0a2438b01926eca936d278cf5b9569200589/h2o-py/h2o/plot/init.py#L2|smart-link] by adding a {{._numpy}} file: [https://github.com/h2oai/h2o-3/blob/046a0a2438b01926eca936d278cf5b9569200589/h2o-py/h2o/plot/_polycollection.py|https://github.com/h2oai/h2o-3/blob/046a0a2438b01926eca936d278cf5b9569200589/h2o-py/h2o/plot/_polycollection.py|smart-link] and then import it here: [https://github.com/h2oai/h2o-3/blob/master/h2o-bindings/bin/custom/python/gen_infogram.py#L44|https://github.com/h2oai/h2o-3/blob/master/h2o-bindings/bin/custom/python/gen_infogram.py#L44|smart-link]

Test this in a venv with numpy not installed.

@exalate-issue-sync
Copy link
Author

Erin LeDell commented: [~accountid:5e43370f5a495e0c91a74ebe] Can you check that my proposal makes sense? Or is there a better way to make numpy available in the {{plot()}} method? Thx.

@exalate-issue-sync
Copy link
Author

Tomas Fryda commented: [~accountid:557058:afd6e9a4-1891-4845-98ea-b5d34a2bc42c] There is a function called {{_get_numpy}}. So it should be possible just to move that function somewhere like {{h2o.utils.ext_dependencies}}. (I think that’s where we had {{get_matplotlib}} before refactoring).

[https://github.com/h2oai/h2o-3/blob/4734a2ce9dcf4886423147ff51454fa49fad5dde/h2o-py/h2o/model/model_base.py#L1785-L1793|https://github.com/h2oai/h2o-3/blob/4734a2ce9dcf4886423147ff51454fa49fad5dde/h2o-py/h2o/model/model_base.py#L1785-L1793|smart-link]

@exalate-issue-sync
Copy link
Author

Erin LeDell commented: I tested this in a venv w/o numpy installed. You will actually hit the matplotlib depedency first, so the error raised is:

{noformat}>>> ig.plot()
Traceback (most recent call last):
File "", line 1, in
File "/Users/me/h2oai/github/h2o-3/venv/lib/python3.8/site-packages/h2o/estimators/infogram.py", line 897, in plot
plt = get_matplotlib_pyplot(server, raise_if_not_available=True)
File "/Users/me/h2oai/github/h2o-3/venv/lib/python3.8/site-packages/h2o/plot/_matplotlib.py", line 27, in get_matplotlib_pyplot
raise e
File "/Users/me/h2oai/github/h2o-3/venv/lib/python3.8/site-packages/h2o/plot/_matplotlib.py", line 5, in get_matplotlib_pyplot
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'{noformat}

@h2o-ops-ro
Copy link
Collaborator

JIRA Issue Details

Jira Issue: PUBDEV-8521
Assignee: Erin LeDell
Reporter: Erin LeDell
State: Resolved
Fix Version: 3.36.0.2
Attachments: N/A
Development PRs: Available

@h2o-ops-ro
Copy link
Collaborator

Linked PRs from JIRA

#6018

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

No branches or pull requests

2 participants