Skip to content

Commit 0a4793e

Browse files
committed
ver 0.15.7.8
miscs
1 parent 32a9e7e commit 0a4793e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

npy/utils/utils_decorator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'return_array', 'return_dict', 'return_list', 'return_attrdict', 'return_dataframe']
1313

1414

15-
def log_function_self(log_args=True):
15+
def log_function_self(log_args=True, log_finish=False):
1616
def decorator(f):
1717
@functools.wraps(f)
1818
def wrapper(*args, **kwargs):
@@ -29,14 +29,17 @@ def wrapper(*args, **kwargs):
2929

3030
sayd(log_str)
3131
result = f(*args, **kwargs)
32+
33+
if log_finish:
34+
sayd(f'Finish: {f.__name__}')
3235
return result
3336

3437
return wrapper
3538

3639
return decorator
3740

3841

39-
def log_function(log_args=True):
42+
def log_function(log_args=True, log_finish=False):
4043
def decorator(f):
4144
@functools.wraps(f)
4245
def wrapper(*args, **kwargs):
@@ -53,6 +56,9 @@ def wrapper(*args, **kwargs):
5356

5457
sayd(log_str)
5558
result = f(*args, **kwargs)
59+
60+
if log_finish:
61+
sayd(f'Finish: {f.__name__}')
5662
return result
5763

5864
return wrapper

npy/utils/utils_primitive/utils_dict.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__all__ = ['keys_d_of_l_of_num', 'keys_d_of_num',
55
'append_d_of_l', 'inv_d', 'replace_keys', 'drop_keys',
66
'filter_d_of_l_of_num', 'filter_d_of_num', 'filter_keys', 'filter_empty',
7-
'dict_eq', 'l_of_dict_eq'
7+
'dict_eq', 'l_of_dict_eq', 'add_d_of_l'
88
]
99

1010

@@ -62,6 +62,18 @@ def append_d_of_l(d_of_l: dict, d: dict):
6262
return d_of_l
6363

6464

65+
def add_d_of_l(d_of_l: dict, d_of_l2: dict, reverse=False):
66+
if d_of_l is None:
67+
return d_of_l2
68+
69+
if reverse:
70+
d_of_l, d_of_l2 = d_of_l2, d_of_l
71+
72+
for key in d_of_l:
73+
d_of_l[key] = d_of_l[key] + d_of_l2[key]
74+
return d_of_l
75+
76+
6577
def inv_d(d: dict) -> dict:
6678
return {v: k for k, v in d.items()}
6779

0 commit comments

Comments
 (0)