From 57d8611ae86cc2cb71d6f1ab973476fc9bea5b7a Mon Sep 17 00:00:00 2001 From: rasbt Date: Wed, 31 Jan 2018 15:14:50 -0500 Subject: [PATCH] fixes newline issue --- CHANGELOG.md | 4 + examples/pyprind_demo.ipynb | 205 ++++++++++++------------------------ pyprind/__init__.py | 2 +- pyprind/prog_class.py | 2 +- 4 files changed, 76 insertions(+), 137 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae1604d..0279e3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +Version 2.11.2 +================ +- Fixes issue where new lines are printed upon iterating over a completed progress bar object. + Version 2.11.1 ================ - Flushes both `stdout` and `stderr` prior to `ProgressBar` initialization to avoid cluttering environments with previously cached print statements. diff --git a/examples/pyprind_demo.ipynb b/examples/pyprind_demo.ipynb index e15da64..828e433 100644 --- a/examples/pyprind_demo.ipynb +++ b/examples/pyprind_demo.ipynb @@ -11,19 +11,19 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "collapsed": false + "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "last updated: 2017-03-01 \n", + "last updated: 2018-01-31 \n", "\n", - "CPython 3.6.0\n", - "IPython 5.3.0\n", + "CPython 3.6.3\n", + "IPython 6.2.1\n", "\n", - "pyprind 2.10.0\n" + "pyprind 2.11.2\n" ] } ], @@ -92,9 +92,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "import pyprind" @@ -133,16 +131,13 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] } @@ -169,17 +164,14 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "while example\n", - "0% 100%\n", - "[##############################]\n" + "0% [##############################] 100%\n" ] }, { @@ -187,8 +179,8 @@ "output_type": "stream", "text": [ "Title: while example\n", - " Started: 03/01/2017 01:10:02\n", - " Finished: 03/01/2017 01:10:07\n", + " Started: 01/31/2018 15:11:30\n", + " Finished: 01/31/2018 15:11:35\n", " Total time elapsed: 00:00:05\n" ] } @@ -246,9 +238,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", @@ -299,16 +289,13 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] } @@ -321,9 +308,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", @@ -372,16 +357,13 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] }, @@ -390,8 +372,8 @@ "output_type": "stream", "text": [ "Title: \n", - " Started: 03/01/2017 01:10:54\n", - " Finished: 03/01/2017 01:10:59\n", + " Started: 01/31/2018 15:11:52\n", + " Finished: 01/31/2018 15:11:57\n", " Total time elapsed: 00:00:05\n" ] } @@ -408,7 +390,6 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [ @@ -417,8 +398,7 @@ "output_type": "stream", "text": [ "Job_1\n", - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] }, @@ -427,11 +407,11 @@ "output_type": "stream", "text": [ "Title: Job_1\n", - " Started: 09/07/2016 21:33:03\n", - " Finished: 09/07/2016 21:33:08\n", + " Started: 01/31/2018 15:11:57\n", + " Finished: 01/31/2018 15:12:02\n", " Total time elapsed: 00:00:05\n", - " CPU %: 2.10\n", - " Memory %: 0.48\n" + " CPU %: 1.90\n", + " Memory %: 0.26\n" ] } ], @@ -485,16 +465,13 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] }, @@ -503,11 +480,11 @@ "output_type": "stream", "text": [ "Title: \n", - " Started: 09/07/2016 21:33:08\n", - " Finished: 09/07/2016 21:33:13\n", + " Started: 01/31/2018 15:12:02\n", + " Finished: 01/31/2018 15:12:08\n", " Total time elapsed: 00:00:05\n", - " CPU %: 1.90\n", - " Memory %: 0.48\n" + " CPU %: 1.80\n", + " Memory %: 0.26\n" ] } ], @@ -529,9 +506,7 @@ { "cell_type": "code", "execution_count": 11, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", @@ -546,11 +521,11 @@ "output_type": "stream", "text": [ "Title: \n", - " Started: 09/07/2016 21:33:13\n", - " Finished: 09/07/2016 21:33:19\n", + " Started: 01/31/2018 15:12:08\n", + " Finished: 01/31/2018 15:12:13\n", " Total time elapsed: 00:00:05\n", - " CPU %: 2.90\n", - " Memory %: 0.48\n" + " CPU %: 6.90\n", + " Memory %: 0.26\n" ] } ], @@ -594,18 +569,15 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": { - "collapsed": false - }, + "execution_count": 12, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "My 1st Progress Bar\n", - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] } @@ -619,10 +591,8 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": { - "collapsed": false - }, + "execution_count": 13, + "metadata": {}, "outputs": [ { "name": "stderr", @@ -673,17 +643,14 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": false - }, + "execution_count": 14, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[##########] | ETA: 00:00:00\n", + "0% [##########] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] } @@ -697,17 +664,14 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": false - }, + "execution_count": 15, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[######################################################################] | ETA: 00:00:00\n", + "0% [######################################################################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] } @@ -751,17 +715,14 @@ }, { "cell_type": "code", - "execution_count": 14, - "metadata": { - "collapsed": false - }, + "execution_count": 16, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] } @@ -775,17 +736,14 @@ }, { "cell_type": "code", - "execution_count": 15, - "metadata": { - "collapsed": false - }, + "execution_count": 17, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:05\n" ] } @@ -799,10 +757,8 @@ }, { "cell_type": "code", - "execution_count": 16, - "metadata": { - "collapsed": false - }, + "execution_count": 18, + "metadata": {}, "outputs": [], "source": [ "import sys\n", @@ -845,16 +801,13 @@ { "cell_type": "code", "execution_count": 19, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[##############################] | ETA: 00:00:00\n", + "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:00\n" ] } @@ -901,16 +854,13 @@ { "cell_type": "code", "execution_count": 20, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[####################] | ETA: 00:00:00 | Item ID: file_20.csv\n", + "0% [####################] 100% | ETA: 00:00:00 | Item ID: file_20.csv\n", "Total time elapsed: 00:00:01\n" ] } @@ -934,9 +884,7 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": false - }, + "metadata": {}, "source": [ "## Choosing your own progress bar style" ] @@ -951,16 +899,13 @@ { "cell_type": "code", "execution_count": 21, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[██████████████████████████████] | ETA: 00:00:00\n", + "0% [██████████████████████████████] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:10\n" ] } @@ -982,9 +927,7 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": false - }, + "metadata": {}, "source": [ "## Controlling the update frequency" ] @@ -1006,16 +949,13 @@ { "cell_type": "code", "execution_count": 22, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[██████████████████████████████] | ETA: 00:00:00\n", + "0% [██████████████████████████████] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:50\n" ] } @@ -1045,16 +985,13 @@ { "cell_type": "code", "execution_count": 23, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "0% 100%\n", - "[██████████████████████████████] | ETA: 00:00:00\n", + "0% [██████████████████████████████] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:20\n" ] } @@ -1070,9 +1007,7 @@ { "cell_type": "code", "execution_count": 24, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stderr", @@ -1108,9 +1043,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.0" + "version": "3.6.3" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 1 } diff --git a/pyprind/__init__.py b/pyprind/__init__.py index ef454f9..9ccc51a 100644 --- a/pyprind/__init__.py +++ b/pyprind/__init__.py @@ -17,4 +17,4 @@ from .generator_factory import prog_bar -__version__ = '2.11.1' +__version__ = '2.11.2' diff --git a/pyprind/prog_class.py b/pyprind/prog_class.py index 6047e88..41a93ad 100644 --- a/pyprind/prog_class.py +++ b/pyprind/prog_class.py @@ -148,7 +148,7 @@ def _get_time(self, _time): def _finish(self): """ Determines if maximum number of iterations (seed) is reached. """ - if self.cnt >= self.max_iter: + if self.active and self.cnt >= self.max_iter: self.total_time = self._elapsed() self.end = time.time() self.last_progress -= 1 # to force a refreshed _print()