zeehio / parmap

Easy to use map and starmap python equivalents
Apache License 2.0
144 stars 9 forks source link

Add options to tqdm.tqdm #29

Closed kaparoo closed 2 years ago

kaparoo commented 2 years ago

Making pm_pbar to be a dictionary would be helpful when multiple progress bar is used (#28).

I tested the new feature by using the given script in parmap.py as follows:

from itertools import product
from parmap import parmap
from tqdm.auto import tqdm

def myfunction(x, y, a, b):
    return (x * y) ** (a * b)

def case1(listx, listy, a, b):
    listz = []
    num_executions = len(listx) * len(listy)
    with tqdm(desc="Case 1", total=num_executions, unit="execution") as pbar:
        for x in listx:
            for y in listy:
                listz.append(myfunction(x, y, a, b))
                pbar.update(1)
    return listz

def case2(listx, listy, a, b):
    tqdm_options={
        "desc": "Case 2",
        "unit": "execution",
    }
    listxy = list(product(listx, listy))  # 'itertools.product' has no len()
    listz = parmap.starmap(myfunction, listxy, a, b, pm_pbar=tqdm_options)
    return listz

if __name__ == "__main__":
    listx = [1, 2, 3, 4, 5, 6]
    listy = [2, 3, 4, 5, 6, 7]
    a = 3.14
    b = 42

    listz1 = case1(listx, listy, a, b)
    listz2 = case2(listx, listy, a, b)

    assert listz1 == listz2

I think it works 😅

kaparoo commented 2 years ago

I'm sorry for the misspelled title of the commit 26ece07🙏

codecov[bot] commented 2 years ago

Codecov Report

Merging #29 (26ece07) into master (4db9f68) will decrease coverage by 0.30%. The diff coverage is 71.42%.

@@            Coverage Diff             @@
##           master      #29      +/-   ##
==========================================
- Coverage   81.09%   80.78%   -0.31%     
==========================================
  Files           2        2              
  Lines         201      203       +2     
==========================================
+ Hits          163      164       +1     
- Misses         38       39       +1     
Impacted Files Coverage Δ
parmap/parmap.py 80.59% <71.42%> (-0.31%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

zeehio commented 2 years ago

Thank you very much! Merged. I will release a new version as soon as I can