byzh-core 0.0.9.2__py3-none-any.whl → 0.0.9.4__py3-none-any.whl
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.
- byzh/core/Brecorder/record2d.py +40 -10
- {byzh_core-0.0.9.2.dist-info → byzh_core-0.0.9.4.dist-info}/METADATA +1 -1
- {byzh_core-0.0.9.2.dist-info → byzh_core-0.0.9.4.dist-info}/RECORD +7 -7
- {byzh_core-0.0.9.2.dist-info → byzh_core-0.0.9.4.dist-info}/LICENSE +0 -0
- {byzh_core-0.0.9.2.dist-info → byzh_core-0.0.9.4.dist-info}/WHEEL +0 -0
- {byzh_core-0.0.9.2.dist-info → byzh_core-0.0.9.4.dist-info}/entry_points.txt +0 -0
- {byzh_core-0.0.9.2.dist-info → byzh_core-0.0.9.4.dist-info}/top_level.txt +0 -0
byzh/core/Brecorder/record2d.py
CHANGED
@@ -2,10 +2,12 @@ import pandas as pd
|
|
2
2
|
from typing import Literal
|
3
3
|
|
4
4
|
from .. import B_os
|
5
|
+
# from byzh.core import B_os
|
5
6
|
|
6
7
|
class B_Record2d:
|
7
|
-
def __init__(self, csv_path, mode:Literal["w", "a"]="
|
8
|
+
def __init__(self, csv_path, mode:Literal["w", "a", "r"]="r"):
|
8
9
|
self.csv_path = csv_path
|
10
|
+
self.mode = mode
|
9
11
|
|
10
12
|
B_os.makedirs(csv_path)
|
11
13
|
self.data = pd.DataFrame()
|
@@ -14,19 +16,45 @@ class B_Record2d:
|
|
14
16
|
self.__read()
|
15
17
|
elif mode == "a":
|
16
18
|
self.__read()
|
19
|
+
elif mode == "r":
|
20
|
+
self.__read()
|
17
21
|
|
18
22
|
# 支持 recorder[row, col] 访问
|
19
23
|
def __getitem__(self, key):
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
if isinstance(key, tuple) and len(key) == 2: # 读值操作
|
25
|
+
row, col = key
|
26
|
+
row, col = str(row), str(col)
|
27
|
+
return self.data.loc[row, col]
|
28
|
+
if isinstance(key, str): # 读行操作
|
29
|
+
row = str(key)
|
30
|
+
return self.data.loc[row, :]
|
23
31
|
|
24
32
|
# 支持 recorder[row, col] = value
|
25
33
|
def __setitem__(self, key, value):
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
assert self.mode!="r", "不允许读模式下赋值"
|
35
|
+
|
36
|
+
if isinstance(key, tuple) and len(key) == 2: # 赋值操作
|
37
|
+
row, col = key
|
38
|
+
row, col, value = str(row), str(col), str(value)
|
39
|
+
self.data.loc[row, col] = value
|
40
|
+
self.__save()
|
41
|
+
if isinstance(key, str): # 赋值行操作
|
42
|
+
assert type(value) == pd.Series, "仅支持 Series 赋值"
|
43
|
+
key = str(key)
|
44
|
+
self.data.loc[key, :] = value.copy()
|
45
|
+
|
46
|
+
# 复制一行
|
47
|
+
def copy_row(self, new_row, origin_row):
|
48
|
+
new_row, origin_row = str(new_row), str(origin_row)
|
49
|
+
|
50
|
+
if origin_row not in self.data.index:
|
51
|
+
raise KeyError(f"源行 {origin_row} 不存在")
|
52
|
+
|
53
|
+
# 深拷贝一份行数据
|
54
|
+
self.data.loc[new_row] = self.data.loc[origin_row].copy()
|
55
|
+
|
29
56
|
self.__save()
|
57
|
+
return self
|
30
58
|
|
31
59
|
# 转置
|
32
60
|
def T(self):
|
@@ -51,10 +79,10 @@ class B_Record2d:
|
|
51
79
|
return float(self[row, col])
|
52
80
|
|
53
81
|
def get_bool(self, row, col) -> bool:
|
54
|
-
result = self[row, col]
|
55
|
-
if result in ("
|
82
|
+
result:str = self[row, col]
|
83
|
+
if result.lower() in ("true", "1"):
|
56
84
|
return True
|
57
|
-
elif result in ("
|
85
|
+
elif result.lower() in ("false", "0"):
|
58
86
|
return False
|
59
87
|
else:
|
60
88
|
raise ValueError(f"无法转换为布尔值 -> {result}")
|
@@ -85,6 +113,8 @@ if __name__ == '__main__':
|
|
85
113
|
recorder["qwq", "OvO"] = 30
|
86
114
|
recorder["qwq", "TwT"] = 40
|
87
115
|
|
116
|
+
recorder['aaa'] = recorder['qwwq']
|
117
|
+
|
88
118
|
print("当前内容:")
|
89
119
|
print(recorder)
|
90
120
|
|
@@ -4,7 +4,7 @@ byzh/core/Barchive/__init__.py,sha256=wUdz646VS0Uhq9lwMkd3YQHCvQhLDqgADoDjFGMqIn
|
|
4
4
|
byzh/core/Barchive/archive.py,sha256=S1hy3qYFEZr5RRmx_Mnq1s2IMUEw973ny1rKSL7J_a0,6721
|
5
5
|
byzh/core/Brecorder/__init__.py,sha256=rYlgYIhr_AcPuGkZRCitbi2_hZYyoERk4XIZ14CU1dk,108
|
6
6
|
byzh/core/Brecorder/record1d.py,sha256=P7y4Gbc0zYcRsZBT4CeYgv35k0tU4h3ED-3H8RQ6cuU,2083
|
7
|
-
byzh/core/Brecorder/record2d.py,sha256=
|
7
|
+
byzh/core/Brecorder/record2d.py,sha256=ZTNDylCHElMBpTLX6BMS6jiDL6gxOOgDxCS8ClJEpzg,3583
|
8
8
|
byzh/core/Btable/__init__.py,sha256=NlQBjp_mvObEUm4y6wXbGipkNM2N3uNIUidaJkTwFsw,62
|
9
9
|
byzh/core/Btable/auto_table.py,sha256=avMeRWydw9L8s3fU0-BSl8a2dCyreIUzW--csm5eR0g,14734
|
10
10
|
byzh/core/Bterminal/__init__.py,sha256=azRLD-kY8Tv2c3llHRBrEJIdVgYw6hAoLgzJeA4PvE0,142
|
@@ -18,9 +18,9 @@ byzh/core/Butils/text_style.py,sha256=34u2-Rsur63iNQ0m7tHxpFWqnQZWybSxBx7vnhOhqD
|
|
18
18
|
byzh/core/Butils/timer.py,sha256=OLxbWWRauYjp1KwavACjoyrqrCciUiIG2ae7qgtZrVA,511
|
19
19
|
byzh/core/Bwriter/__init__.py,sha256=QcHzKs0305Pr78ZvZgcC_4miSYZh8jJQDt5TD0GIeEg,82
|
20
20
|
byzh/core/Bwriter/writer.py,sha256=ss9EWo-l7czBUlY7Fu0buvQgO5fRspYKtC2X6eaRa0c,3213
|
21
|
-
byzh_core-0.0.9.
|
22
|
-
byzh_core-0.0.9.
|
23
|
-
byzh_core-0.0.9.
|
24
|
-
byzh_core-0.0.9.
|
25
|
-
byzh_core-0.0.9.
|
26
|
-
byzh_core-0.0.9.
|
21
|
+
byzh_core-0.0.9.4.dist-info/LICENSE,sha256=-nRwf0Xga4AX5bsWBXXflpDpgX_U23X06oAMcdf0dSY,1089
|
22
|
+
byzh_core-0.0.9.4.dist-info/METADATA,sha256=kRwb5ZY4jfHaQpeziehogqYw4DuQ16ZySTxD9M5dNyY,371
|
23
|
+
byzh_core-0.0.9.4.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
24
|
+
byzh_core-0.0.9.4.dist-info/entry_points.txt,sha256=qoN3Uvulj0BcOQVDqsFqP2dBVQzG1QrUtC5wFsghSLo,51
|
25
|
+
byzh_core-0.0.9.4.dist-info/top_level.txt,sha256=tmaFVY8uApe6apOETSOgwz-4v5Mj4uxgRT8yNnDNZNA,5
|
26
|
+
byzh_core-0.0.9.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|