Skip to content

Commit

Permalink
chore(eda): polish progress_bar
Browse files Browse the repository at this point in the history
  • Loading branch information
dovahcrow committed Sep 4, 2020
1 parent d005d3d commit a0bafdb
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions dataprep/eda/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,13 @@ def _pretask(
if self._started is None:
raise ValueError("ProgressBar not started properly")

if self._pbar is None and time() - self._started > self._minimum:
if self._pbar is None and then - self._started > self._minimum:
self._init_pbar()

if isinstance(key, tuple):
key = key[0]

if self._pbar is not None:
if self._last_updated is None:
raise ValueError("ProgressBar not started properly")

if time() - self._last_updated > self._interval:
self._pbar.set_description(f"Computing {key}")
self._last_updated = time()
else:
self._last_task = key
self._last_task = key

self._pbar_runtime += time() - then

Expand Down Expand Up @@ -155,7 +147,10 @@ def _finish(self, _dsk: Any, _state: Dict[str, Any], _errored: bool) -> None:

self._pbar_runtime += time() - then

if self._pbar_runtime / (time() - self._started) > 0.3:
if (
self._pbar_runtime > 0.1 * (time() - self._started)
and self._pbar_runtime > 1
):
print(
"[ProgressBar] ProgressBar takes additional 10%+ of the computation time,"
" consider disable it by passing 'progress=False' to the plot function.",
Expand All @@ -171,6 +166,7 @@ def _update_bar(self) -> None:
return
ndone, _ = self._count_tasks()

self._pbar.set_description(f"Computing {self._last_task}", refresh=False)
self._pbar.update(max(0, ndone - self._pbar.n))

def _init_pbar(self) -> None:
Expand All @@ -189,17 +185,16 @@ def _init_pbar(self) -> None:
dynamic_ncols=True,
mininterval=self._interval,
initial=ndone,
desc=desc,
)
else:
self._pbar = tqdm(
total=ntasks,
ncols=self._width,
mininterval=self._interval,
initial=ndone,
desc=desc,
)

self._pbar.set_description(desc)
self._pbar.start_t = self._started
self._pbar.refresh()

Expand Down

0 comments on commit a0bafdb

Please sign in to comment.