Skip to content

Commit

Permalink
bump version, Merge branch 'unit_scale'
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jul 22, 2017
2 parents 2189a2b + b98ca19 commit 45caa70
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 63 deletions.
7 changes: 4 additions & 3 deletions README.rst
Expand Up @@ -309,11 +309,12 @@ Parameters
* unit : str, optional
String that will be used to define the unit of each iteration
[default: it].
* unit_scale : bool, optional
If set, the number of iterations will be reduced/scaled
* unit_scale : bool or int or float, optional
If 1 or True, the number of iterations will be reduced/scaled
automatically and a metric prefix following the
International System of Units standard will be added
(kilo, mega, etc.) [default: False].
(kilo, mega, etc.) [default: False]. If any other non-zero
number, will scale `total` and `n`.
* dynamic_ncols : bool, optional
If set, constantly alters ``ncols`` to the environment (allowing
for window resizes) [default: False].
Expand Down
20 changes: 14 additions & 6 deletions tqdm/_tqdm.py
Expand Up @@ -229,10 +229,11 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
(1-9 #).
unit : str, optional
The iteration unit [default: 'it'].
unit_scale : bool, optional
If set, the number of iterations will printed with an
unit_scale : bool or int or float, optional
If 1 or True, the number of iterations will be printed with an
appropriate SI metric prefix (K = 10^3, M = 10^6, etc.)
[default: False].
[default: False]. If any other non-zero number, will scale
`total` and `n`.
rate : float, optional
Manual override for iteration rate.
If [default: None], uses n/elapsed.
Expand All @@ -257,6 +258,12 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
if total and n > total:
total = None

# apply custom scale if necessary
if unit_scale and unit_scale not in (True, 1):
total *= unit_scale
n *= unit_scale
unit_scale = False

format_interval = tqdm.format_interval
elapsed_str = format_interval(elapsed)

Expand Down Expand Up @@ -613,11 +620,12 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True,
unit : str, optional
String that will be used to define the unit of each iteration
[default: it].
unit_scale : bool, optional
If set, the number of iterations will be reduced/scaled
unit_scale : bool or int or float, optional
If 1 or True, the number of iterations will be reduced/scaled
automatically and a metric prefix following the
International System of Units standard will be added
(kilo, mega, etc.) [default: False].
(kilo, mega, etc.) [default: False]. If any other non-zero
number, will scale `total` and `n`.
dynamic_ncols : bool, optional
If set, constantly alters `ncols` to the environment (allowing
for window resizes) [default: False].
Expand Down
2 changes: 1 addition & 1 deletion tqdm/_version.py
Expand Up @@ -5,7 +5,7 @@
__all__ = ["__version__"]

# major, minor, patch, -extra
version_info = 4, 14, 0
version_info = 4, 15, 0

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
Expand Down
2 changes: 1 addition & 1 deletion tqdm/tests/tests_main.py
Expand Up @@ -13,7 +13,7 @@ def _sh(*cmd, **kwargs):
# WARNING: this should be the last test as it messes with sys.stdin, argv
@with_setup(pretest, posttest)
def test_main():
""" Test command line pipes """
"""Test command line pipes"""
ls_out = _sh('ls').replace('\r\n', '\n')
ls = subprocess.Popen(('ls'),
stdout=subprocess.PIPE,
Expand Down
10 changes: 5 additions & 5 deletions tqdm/tests/tests_pandas.py
Expand Up @@ -6,7 +6,7 @@

@with_setup(pretest, posttest)
def test_pandas_groupby_apply():
""" Test pandas.DataFrame.groupby(...).progress_apply """
"""Test pandas.DataFrame.groupby(...).progress_apply"""
try:
from numpy.random import randint
import pandas as pd
Expand Down Expand Up @@ -36,7 +36,7 @@ def test_pandas_groupby_apply():

@with_setup(pretest, posttest)
def test_pandas_apply():
""" Test pandas.DataFrame[.series].progress_apply """
"""Test pandas.DataFrame[.series].progress_apply"""
try:
from numpy.random import randint
import pandas as pd
Expand All @@ -62,7 +62,7 @@ def test_pandas_apply():

@with_setup(pretest, posttest)
def test_pandas_map():
""" Test pandas.Series.progress_map """
"""Test pandas.Series.progress_map"""
try:
from numpy.random import randint
import pandas as pd
Expand All @@ -82,7 +82,7 @@ def test_pandas_map():

@with_setup(pretest, posttest)
def test_pandas_leave():
""" Test pandas with `leave=True` """
"""Test pandas with `leave=True`"""
try:
from numpy.random import randint
import pandas as pd
Expand All @@ -105,7 +105,7 @@ def test_pandas_leave():

@with_setup(pretest, posttest)
def test_pandas_deprecation():
""" Test bar object instance as argument deprecation """
"""Test bar object instance as argument deprecation"""
try:
from numpy.random import randint
from tqdm import tqdm_pandas
Expand Down
20 changes: 10 additions & 10 deletions tqdm/tests/tests_perf.py
Expand Up @@ -25,14 +25,14 @@ def get_relative_time(prevtime=0):


def cpu_sleep(t):
'''Sleep the given amount of cpu time'''
"""Sleep the given amount of cpu time"""
start = process_time()
while((process_time() - start) < t):
pass


def checkCpuTime(sleeptime=0.2):
'''Check if cpu time works correctly'''
"""Check if cpu time works correctly"""
if checkCpuTime.passed:
return True
# First test that sleeping does not consume cputime
Expand Down Expand Up @@ -85,14 +85,14 @@ def test_inner():


class MockIO(StringIO):
""" Wraps StringIO to mock a file with no I/O """
"""Wraps StringIO to mock a file with no I/O"""
def write(self, data):
return


def simple_progress(iterable=None, total=None, file=sys.stdout, desc='',
leave=False, miniters=1, mininterval=0.1, width=60):
""" Simple progress bar reproducing tqdm's major features """
"""Simple progress bar reproducing tqdm's major features"""
n = [0] # use a closure
start_t = [time()]
last_n = [0]
Expand Down Expand Up @@ -160,7 +160,7 @@ def update_and_yield():
@with_setup(pretest, posttest)
@retry_on_except()
def test_iter_overhead():
""" Test overhead of iteration based tqdm """
"""Test overhead of iteration based tqdm"""

total = int(1e6)

Expand All @@ -186,7 +186,7 @@ def test_iter_overhead():
@with_setup(pretest, posttest)
@retry_on_except()
def test_manual_overhead():
""" Test overhead of manual tqdm """
"""Test overhead of manual tqdm"""

total = int(1e6)

Expand All @@ -213,7 +213,7 @@ def test_manual_overhead():
@with_setup(pretest, posttest)
@retry_on_except()
def test_iter_overhead_hard():
""" Test overhead of iteration based tqdm (hard) """
"""Test overhead of iteration based tqdm (hard)"""

total = int(1e5)

Expand Down Expand Up @@ -242,7 +242,7 @@ def test_iter_overhead_hard():
@with_setup(pretest, posttest)
@retry_on_except()
def test_manual_overhead_hard():
""" Test overhead of manual tqdm (hard) """
"""Test overhead of manual tqdm (hard)"""

total = int(1e5)

Expand Down Expand Up @@ -272,7 +272,7 @@ def test_manual_overhead_hard():
@with_setup(pretest, posttest)
@retry_on_except()
def test_iter_overhead_simplebar_hard():
""" Test overhead of iteration based tqdm vs simple progress bar (hard) """
"""Test overhead of iteration based tqdm vs simple progress bar (hard)"""

total = int(1e4)

Expand Down Expand Up @@ -302,7 +302,7 @@ def test_iter_overhead_simplebar_hard():
@with_setup(pretest, posttest)
@retry_on_except()
def test_manual_overhead_simplebar_hard():
""" Test overhead of manual tqdm vs simple progress bar (hard) """
"""Test overhead of manual tqdm vs simple progress bar (hard)"""

total = int(1e4)

Expand Down

0 comments on commit 45caa70

Please sign in to comment.