Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1079 from tqdm/dask
- Loading branch information
Showing
10 changed files
with
122 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import division | ||
|
||
from time import sleep | ||
|
||
from .tests_tqdm import importorskip, mark | ||
|
||
pytestmark = mark.slow | ||
|
||
|
||
def test_dask(capsys): | ||
"""Test tqdm.dask.TqdmCallback""" | ||
ProgressBar = importorskip('tqdm.dask').TqdmCallback | ||
dask = importorskip('dask') | ||
|
||
schedule = [dask.delayed(sleep)(i / 10) for i in range(5)] | ||
with ProgressBar(): | ||
dask.compute(schedule) | ||
_, err = capsys.readouterr() | ||
assert '5/5' in err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import absolute_import | ||
|
||
from functools import partial | ||
|
||
from dask.callbacks import Callback | ||
|
||
from .auto import tqdm as tqdm_auto | ||
|
||
__author__ = {"github.com/": ["casperdcl"]} | ||
__all__ = ['TqdmCallback'] | ||
|
||
|
||
class TqdmCallback(Callback): | ||
"""Dask callback for task progress.""" | ||
def __init__(self, start=None, pretask=None, tqdm_class=tqdm_auto, | ||
**tqdm_kwargs): | ||
""" | ||
Parameters | ||
---------- | ||
tqdm_class : optional | ||
`tqdm` class to use for bars [default: `tqdm.auto.tqdm`]. | ||
tqdm_kwargs : optional | ||
Any other arguments used for all bars. | ||
""" | ||
super(TqdmCallback, self).__init__(start=start, pretask=pretask) | ||
if tqdm_kwargs: | ||
tqdm_class = partial(tqdm_class, **tqdm_kwargs) | ||
self.tqdm_class = tqdm_class | ||
|
||
def _start_state(self, _, state): | ||
self.pbar = self.tqdm_class(total=sum( | ||
len(state[k]) for k in ['ready', 'waiting', 'running', 'finished'])) | ||
|
||
def _posttask(self, *_, **__): | ||
self.pbar.update() | ||
|
||
def _finish(self, *_, **__): | ||
self.pbar.close() | ||
|
||
def display(self): | ||
"""Displays in the current cell in Notebooks.""" | ||
container = getattr(self.bar, 'container', None) | ||
if container is None: | ||
return | ||
from .notebook import display | ||
display(container) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters