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

GH-15584: Fix python explain re-rendering [nocheck] #15586

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions h2o-py/h2o/explanation/_explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _dont_display(object):
"""
import matplotlib.figure
plt = get_matplotlib_pyplot(False, raise_if_not_available=True)
if isinstance(object, matplotlib.figure.Figure):
if isinstance(object, matplotlib.figure.Figure) or is_decorated_plot_result(object) and (object.figure() is not None):
plt.close()
return object

Expand Down Expand Up @@ -179,7 +179,10 @@ class H2OExplanation(OrderedDict):
def _ipython_display_(self):
from IPython.display import display
for v in self.values():
display(v)
if is_decorated_plot_result(v):
display(v.figure())
else:
display(v)


@contextmanager
Expand Down
11 changes: 10 additions & 1 deletion h2o-py/h2o/plot/_plot_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@

__no_export = set(dir()) # all variables defined above this are not exported


class _MObject(object): pass


class _MTuple(tuple): pass


class _MList(list): pass


class _MDict(dict): pass


class _MStr(str): pass


Expand All @@ -31,7 +40,7 @@ def get_figure():
dec = _MDict(res)
elif isinstance(res, str):
dec = _MStr(res)
else: # should be an H2O instance, should be mutable
else: # should be an H2O instance, should be mutable
dec = res
dec.figure = get_figure
dec._is_decorated_plot_result = True
Expand Down