From 212f67b4cfbe81970a737d8b067436d20eb2df4f Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 16 Nov 2015 19:55:21 +0000 Subject: [PATCH] fixes #54 --- README.rst | 4 ++-- tqdm/_tqdm.py | 10 ++++++---- tqdm/tests/tests_tqdm.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 8621a6a7..e0d9fbe1 100644 --- a/README.rst +++ b/README.rst @@ -71,7 +71,7 @@ Documentation def __init__(self, iterable=None, desc=None, total=None, leave=False, file=sys.stderr, ncols=None, mininterval=0.1, miniters=None, ascii=None, disable=False, unit='it', unit_scale=False, - dynamic_ncols=False, smoothing=0.05): + dynamic_ncols=False, smoothing=0.3): Parameters ~~~~~~~~~~ @@ -124,7 +124,7 @@ Parameters * smoothing : float Exponential moving average smoothing factor for speed estimates (ignored in GUI mode). Ranges from 0 (average speed) to 1 - (current/instantaneous speed) [default: 0.05]. + (current/instantaneous speed) [default: 0.3]. Returns ~~~~~~~ diff --git a/tqdm/_tqdm.py b/tqdm/_tqdm.py index da049dd8..21175050 100644 --- a/tqdm/_tqdm.py +++ b/tqdm/_tqdm.py @@ -210,7 +210,7 @@ class tqdm(object): def __init__(self, iterable=None, desc=None, total=None, leave=False, file=sys.stderr, ncols=None, mininterval=0.1, miniters=None, ascii=None, disable=False, unit='it', unit_scale=False, - dynamic_ncols=False, smoothing=0.05, gui=False): + dynamic_ncols=False, smoothing=0.3, gui=False): """ Parameters ---------- @@ -261,7 +261,7 @@ class tqdm(object): smoothing : float Exponential moving average smoothing factor for speed estimates (ignored in GUI mode). Ranges from 0 (average speed) to 1 - (current/instantaneous speed) [default: 0.05]. + (current/instantaneous speed) [default: 0.3]. gui : bool, optional WARNING: internal paramer - do not use. Use tqdm_gui(...) instead. If set, will attempt to use matplotlib animations for a @@ -397,7 +397,8 @@ class tqdm(object): # If no `miniters` was specified, adjust automatically # to the maximum iteration rate seen so far. if dynamic_miniters: - miniters = max(miniters, delta_it) + miniters = smoothing * delta_it + \ + (1 - smoothing) * miniters # Store old values for next call last_print_n = n @@ -467,7 +468,8 @@ class tqdm(object): # calls to `tqdm.update()` will only cause an update after # at least 5 more iterations. if self.dynamic_miniters: - self.miniters = max(self.miniters, delta_it) + self.miniters = self.smoothing * delta_it + \ + (1 - self.smoothing) * self.miniters # Store old values for next call self.last_print_n = self.n diff --git a/tqdm/tests/tests_tqdm.py b/tqdm/tests/tests_tqdm.py index 104e9676..3e226774 100644 --- a/tqdm/tests/tests_tqdm.py +++ b/tqdm/tests/tests_tqdm.py @@ -183,7 +183,7 @@ def test_dynamic_min_iters(): """ Test purely dynamic miniters """ our_file = StringIO() total = 10 - t = tqdm(total=total, file=our_file, miniters=None, mininterval=0) + t = tqdm(total=total, file=our_file, miniters=None, mininterval=0, smoothing=1) t.update() # Increase 3 iterations