Skip to content

Commit

Permalink
re-adding widget progressbar (#460)
Browse files Browse the repository at this point in the history
* readded_widgets

* v0

* added_kaggle_comment

* added_kaggle_comment

* linting

* linting

* merge
  • Loading branch information
JKL98ISR committed Jan 4, 2022
1 parent 63af15f commit c917845
Show file tree
Hide file tree
Showing 7 changed files with 3,678 additions and 1,441 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Using pip

.. code:: bash
pip install deepchecks #--upgrade --user
pip install deepchecks -U --user
Using conda
~~~~~~~~~~~
Expand Down
10 changes: 8 additions & 2 deletions deepchecks/base/display_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from IPython.core.display import display_html

from deepchecks import errors
from deepchecks.utils.ipython import is_widgets_enabled
from deepchecks.utils.strings import get_random_string
from deepchecks.base.check import CheckResult, CheckFailure
from deepchecks.base.display_pandas import dataframe_to_html, display_conditions_table
Expand All @@ -31,8 +32,13 @@ class ProgressBar:

def __init__(self, name, length):
"""Initialize progress bar."""
self.pbar = tqdm.tqdm(total=length, desc=name, unit='Check', leave=False, file=sys.stdout,
bar_format=f'{{l_bar}}{{bar:{length}}}{{r_bar}}')
shared_args = {'total': length, 'desc': name, 'unit': ' Check', 'leave': False, 'file': sys.stdout}
if is_widgets_enabled():
self.pbar = tqdm.tqdm_notebook(**shared_args, colour='#9d60fb')
else:
# Normal tqdm with colour in notebooks produce bug that the cleanup doesn't remove all characters. so
# until bug fixed, doesn't add the colour to regular tqdm
self.pbar = tqdm.tqdm(**shared_args, bar_format=f'{{l_bar}}{{bar:{length}}}{{r_bar}}')

def set_text(self, text):
"""Set current running check."""
Expand Down
25 changes: 23 additions & 2 deletions deepchecks/utils/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
# ----------------------------------------------------------------------------
#
"""Utils module containing useful global functions."""
import re
import subprocess
import sys
from functools import lru_cache
from importlib import import_module


from IPython import get_ipython # TODO: I think we should remove ipython from mandatory dependencies


__all__ = ['is_notebook', 'is_ipython_display']
__all__ = ['is_notebook', 'is_ipython_display', 'is_widgets_enabled']


@lru_cache(maxsize=None)
Expand Down Expand Up @@ -46,3 +47,23 @@ def is_ipython_display() -> bool:
# pylint: disable=broad-except
except Exception:
return False


@lru_cache(maxsize=None)
def is_widgets_enabled() -> bool:
"""Check if we're running in jupyter and having jupyter widgets extension enabled."""
if not is_notebook():
return False
else:
# Test if widgets extension are in list
try:
# The same widget can appear multiple times from different config locations, than if there are both
# disabled and enabled, regard it as disabled
output = subprocess.getoutput('jupyter nbextension list').split('\n')
disabled_regex = re.compile(r'\s*(jupyter-js-widgets/extension).*(disabled).*')
enabled_regex = re.compile(r'\s*(jupyter-js-widgets/extension).*(enabled).*')
found_disabled = any((disabled_regex.match(s) for s in output))
found_enabled = any((enabled_regex.match(s) for s in output))
return not found_disabled and found_enabled
except Exception: # pylint: disable=broad-except
return False
2 changes: 1 addition & 1 deletion docs/source/getting-started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Simply run the following command in a notebook cell:

.. code-block:: bash
!pip install deepchecks
!pip install deepchecks -U --user
Expand Down

0 comments on commit c917845

Please sign in to comment.