-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
48 lines (33 loc) · 939 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from logging_tqdm import tqdm
import time
print("Testing tqdm-logging:")
for i in tqdm(range(100)):
time.sleep(.02)
print("\n\n\n")
print("Testing tqdm-logging with exception:")
try:
for i in tqdm(range(100)):
if i == 75:
raise Exception("Some Exception")
time.sleep(.02)
except:
pass
print("\n\n\n")
import pandas as pd
import numpy as np
tqdm.pandas()
print("Testing pandas tqdm-logging:")
print("Processing 10 groups (needs 11 pandas operations):")
df=pd.DataFrame({'classes':np.random.randint(0,10,size=1000), \
'data':np.random.randn(1000)})
df.groupby('classes').progress_apply(lambda x:(time.sleep(.2),x.mean)[1])
print("\n\n\n")
print("Testing pandas tqdm-logging with exception:")
c=0
def exceptionMean(groupData):
global c
c+=1
if c==7:
raise Exception("")
return groupData.mean()
df.groupby('classes').progress_apply(exceptionMean)