Skip to content

Commit

Permalink
GH-15584: Fix python explain re-rendering [nocheck] (#15586)
Browse files Browse the repository at this point in the history
* Fix python explain re-rendering

* Do not render images when render=False
  • Loading branch information
tomasfryda committed Jun 26, 2023
1 parent 1b58c7e commit 65eceb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit 65eceb8

Please sign in to comment.