lime icon indicating copy to clipboard operation
lime copied to clipboard

Deprecation Warning for Ipython

Open Alex-Wenner-FHR opened this issue 3 years ago • 2 comments

I see this error when running show_in_notebook():

/opt/miniconda3/lib/python3.9/site-packages/lime/explanation.py:194:
DeprecationWarning: Importing display from 
IPython.core.display is deprecated since IPython 7.14, 
please import from IPython display
  from IPython.core.display import display, HTML

Appears to be coming from line 194 explanation.py

This also prevents the table from rendering!

Alex-Wenner-FHR avatar Oct 26 '22 15:10 Alex-Wenner-FHR

With the release of IPython 9, this now breaks.

>>> from IPython.core.display import display
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'display' from 'IPython.core.display' (/Users/petergedeck/git/mlba-python-notebooks/.venv/lib/python3.12/site-packages/IPython/core/display.py)

With IPython 8, the error message is:

>>> from IPython.core.display import display
<stdin>:1: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython.display

It's trivial to fix

    def show_in_notebook(self,
                         labels=None,
                         predict_proba=True,
                         show_predicted_value=True,
                         **kwargs):
        """Shows html explanation in ipython notebook.

        See as_html() for parameters.
        This will throw an error if you don't have IPython installed"""

        from IPython.display import display, HTML
        display(HTML(self.as_html(labels=labels,
                                  predict_proba=predict_proba,
                                  show_predicted_value=show_predicted_value,
                                  **kwargs)))

gedeck avatar Mar 13 '25 15:03 gedeck

A trivial workaround may be to just call

display(HTML(exp.as_html()))

instead of

exp.show_in_notebook()

baraldian avatar Apr 16 '25 10:04 baraldian