Fix progbar dynamic display
@@ -267,7 +267,8 @@ class Progbar(object):
self.total_width = 0
self.seen_so_far = 0
self.verbose = verbose
- self.is_jupyter = 'ipykernel' in sys.modules
+ self._dynamic_display = (sys.stdout.isatty() or
+ 'ipykernel' in sys.modules)
def update(self, current, values=None, force=False):
"""Updates the progress bar.
@@ -297,7 +298,7 @@ class Progbar(object):
return
prev_total_width = self.total_width
- if sys.stdout.isatty() or self.is_jupyter:
+ if self._dynamic_display:
sys.stdout.write('\b' * prev_total_width)
sys.stdout.write('\r')
else:
@@ -348,7 +349,8 @@ class Progbar(object):
for k in self.unique_values:
info += ' - %s:' % k
if isinstance(self.sum_values[k], list):
- avg = np.mean(self.sum_values[k][0] / max(1, self.sum_values[k][1]))
+ avg = np.mean(
+ self.sum_values[k][0] / max(1, self.sum_values[k][1]))
if abs(avg) > 1e-3:
info += ' %.4f' % avg
else:
@@ -370,7 +372,8 @@ class Progbar(object):
if self.target is None or current >= self.target:
for k in self.unique_values:
info += ' - %s:' % k
- avg = np.mean(self.sum_values[k][0] / max(1, self.sum_values[k][1]))
+ avg = np.mean(
+ self.sum_values[k][0] / max(1, self.sum_values[k][1]))
if avg > 1e-3:
info += ' %.4f' % avg
else:
