Muyi 0.0.7__tar.gz → 0.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Muyi
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: Some useful utils.
5
5
  Home-page: https://github.com/Muyiiiii/muyi
6
6
  Author: muyiiiii
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Muyi
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: Some useful utils.
5
5
  Home-page: https://github.com/Muyiiiii/muyi
6
6
  Author: muyiiiii
@@ -0,0 +1,102 @@
1
+ import os
2
+ import matplotlib.pyplot as plt
3
+ import pandas as pd
4
+ from tqdm import tqdm
5
+ import sys
6
+
7
+ class bcolors:
8
+ HEADER = '\033[95m' # 紫色,用于标题
9
+ OKBLUE = '\033[94m' # 蓝色,用于正常或信息性消息
10
+ OKCYAN = '\033[96m' # 青色(浅蓝色),用于信息性消息
11
+ OKGREEN = '\033[92m' # 绿色,用于成功或确认的消息
12
+ WARNING = '\033[93m' # 黄色,用于警告或重要提示
13
+ FAIL = '\033[91m' # 红色,用于错误或失败的消息
14
+ ENDC = '\033[0m' # 重置所有样式,回到默认颜色
15
+ BOLD = '\033[1m' # 粗体文本
16
+ UNDERLINE = '\033[4m' # 下划线文本
17
+ BLACK = '\033[30m' # 黑色
18
+ RED = '\033[31m' # 红色
19
+ GREEN = '\033[32m' # 绿色
20
+ YELLOW = '\033[33m' # 黄色
21
+ BLUE = '\033[34m' # 蓝色
22
+ MAGENTA = '\033[35m' # 品红色(紫红色)
23
+ CYAN = '\033[36m' # 青色
24
+ WHITE = '\033[37m' # 白色
25
+ # 添加背景颜色
26
+ BG_BLACK = '\033[40m' # 黑色背景
27
+ BG_RED = '\033[41m' # 红色背景
28
+ BG_GREEN = '\033[42m' # 绿色背景
29
+ BG_YELLOW = '\033[43m' # 黄色背景
30
+ BG_BLUE = '\033[44m' # 蓝色背景
31
+ BG_MAGENTA = '\033[45m'# 品红色(紫红色)背景
32
+ BG_CYAN = '\033[46m' # 青色背景
33
+ BG_WHITE = '\033[47m' # 白色背景
34
+
35
+
36
+ def color_print(content, font_color='white', bg_color='bg_blue'):
37
+ colors = {
38
+ 'header': bcolors.HEADER,
39
+ 'okblue': bcolors.OKBLUE,
40
+ 'okcyan': bcolors.OKCYAN,
41
+ 'okgreen': bcolors.OKGREEN,
42
+ 'warning': bcolors.WARNING,
43
+ 'fail': bcolors.FAIL,
44
+ 'black': bcolors.BLACK,
45
+ 'red': bcolors.RED,
46
+ 'green': bcolors.GREEN,
47
+ 'yellow': bcolors.YELLOW,
48
+ 'blue': bcolors.BLUE,
49
+ 'magenta': bcolors.MAGENTA,
50
+ 'cyan': bcolors.CYAN,
51
+ 'white': bcolors.WHITE,
52
+ 'bg_black': bcolors.BG_BLACK,
53
+ 'bg_red': bcolors.BG_RED,
54
+ 'bg_green': bcolors.BG_GREEN,
55
+ 'bg_yellow': bcolors.BG_YELLOW,
56
+ 'bg_blue': bcolors.BG_BLUE,
57
+ 'bg_magenta': bcolors.BG_MAGENTA,
58
+ 'bg_cyan': bcolors.BG_CYAN,
59
+ 'bg_white': bcolors.BG_WHITE,
60
+ 'end': bcolors.ENDC,
61
+ }
62
+
63
+ # Apply the background color first, then the font color
64
+ print(f'{colors[bg_color]}{colors[font_color]}{content}{colors["end"]}\n')
65
+
66
+ def save_pic_iterly(pic_name, postfix, info):
67
+ pic_idx=1
68
+ pic_name_full=f'{pic_name}_{pic_idx}.{postfix}'
69
+
70
+ while os.path.exists(pic_name_full):
71
+ print(f'File {pic_name_full} already exists.')
72
+ pic_idx += 1
73
+ pic_name_full=f'{pic_name}_{pic_idx}.png'
74
+
75
+ plt.savefig(pic_name_full, dpi=300, bbox_inches='tight')
76
+
77
+ color_print(f'!!!!! {info} is saved in file {pic_name_full}')
78
+
79
+ def read_csv_tqdm(path, **kwargs):
80
+ INPUT_FILENAME = path
81
+ LINES_TO_READ_FOR_ESTIMATION = 20
82
+ CHUNK_SIZE_PER_ITERATION = 10**5
83
+
84
+
85
+ temp = pd.read_csv(INPUT_FILENAME,
86
+ nrows=LINES_TO_READ_FOR_ESTIMATION, **kwargs)
87
+ N = len(temp.to_csv(index=False))
88
+ df = [temp[:0]]
89
+ t = int(os.path.getsize(INPUT_FILENAME)/N*LINES_TO_READ_FOR_ESTIMATION/CHUNK_SIZE_PER_ITERATION) + 1
90
+
91
+
92
+ with tqdm(total = t, file = sys.stdout) as pbar:
93
+ for i,chunk in enumerate(pd.read_csv(INPUT_FILENAME, chunksize=CHUNK_SIZE_PER_ITERATION, low_memory=False, **kwargs)):
94
+ df.append(chunk)
95
+ pbar.set_description('Importing: %d' % (1 + i))
96
+ pbar.update(1)
97
+
98
+ # data = temp[:0].append(df)
99
+ data = pd.concat(df)
100
+
101
+ del df
102
+ return data
@@ -3,7 +3,7 @@ with open("README.md", "r") as fh:
3
3
  long_description = fh.read()
4
4
  setuptools.setup(
5
5
  name="Muyi", # 模块名称
6
- version="0.0.7", # 当前版本
6
+ version="0.0.8", # 当前版本
7
7
  author="muyiiiii", # 作者
8
8
  author_email="", # 作者邮箱
9
9
  description="Some useful utils.", # 模块简介
muyi-0.0.7/muyi/utils.py DELETED
@@ -1,46 +0,0 @@
1
- import os
2
- import matplotlib.pyplot as plt
3
- import pandas as pd
4
- from tqdm import tqdm
5
- import sys
6
-
7
- def color_print(content):
8
- print(f'\033[1;46m{content}\033[0m\n')
9
-
10
- def save_pic_iterly(pic_name, postfix, info):
11
- pic_idx=1
12
- pic_name_full=f'{pic_name}_{pic_idx}.{postfix}'
13
-
14
- while os.path.exists(pic_name_full):
15
- print(f'File {pic_name_full} already exists.')
16
- pic_idx += 1
17
- pic_name_full=f'{pic_name}_{pic_idx}.png'
18
-
19
- plt.savefig(pic_name_full, dpi=300, bbox_inches='tight')
20
-
21
- color_print(f'!!!!! {info} is saved in file {pic_name_full}')
22
-
23
- def read_csv_tqdm(path, **kwargs):
24
- INPUT_FILENAME = path
25
- LINES_TO_READ_FOR_ESTIMATION = 20
26
- CHUNK_SIZE_PER_ITERATION = 10**5
27
-
28
-
29
- temp = pd.read_csv(INPUT_FILENAME,
30
- nrows=LINES_TO_READ_FOR_ESTIMATION, **kwargs)
31
- N = len(temp.to_csv(index=False))
32
- df = [temp[:0]]
33
- t = int(os.path.getsize(INPUT_FILENAME)/N*LINES_TO_READ_FOR_ESTIMATION/CHUNK_SIZE_PER_ITERATION) + 1
34
-
35
-
36
- with tqdm(total = t, file = sys.stdout) as pbar:
37
- for i,chunk in enumerate(pd.read_csv(INPUT_FILENAME, chunksize=CHUNK_SIZE_PER_ITERATION, low_memory=False, **kwargs)):
38
- df.append(chunk)
39
- pbar.set_description('Importing: %d' % (1 + i))
40
- pbar.update(1)
41
-
42
- # data = temp[:0].append(df)
43
- data = pd.concat(df)
44
-
45
- del df
46
- return data
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes