Skip to content

Commit

Permalink
添加日志
Browse files Browse the repository at this point in the history
  • Loading branch information
wukan1986 committed Jan 12, 2025
1 parent 43ccc91 commit 53c2166
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions examples/demo_tdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def _code_block_2():
# =====================================
logger.info('计算开始')
t1 = time.perf_counter()
df = codegen_exec(df, _code_block_1, _code_block_2, output_file='1_out.py', run_file=False)
df = codegen_exec(df, _code_block_1, _code_block_2, output_file='1_out.py', run_file=False, over_null=None)
t2 = time.perf_counter()
df = codegen_exec(df, _code_block_1, _code_block_2, output_file='1_out.py', run_file=True)
df = codegen_exec(df, _code_block_1, _code_block_2, output_file='1_out.py', run_file=True, over_null=None)
t3 = time.perf_counter()
df = codegen_exec(df, _code_block_1, _code_block_2, output_file='1_out.py', run_file=True)
df = codegen_exec(df, _code_block_1, _code_block_2, output_file='1_out.py', run_file=True, over_null=None)
t4 = time.perf_counter()
print(t2 - t1, t3 - t2, t4 - t3)
logger.info('计算结束')
Expand Down
2 changes: 1 addition & 1 deletion expr_codegen/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.10"
__version__ = "0.10.11"
16 changes: 14 additions & 2 deletions expr_codegen/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def all(self, exprs_src, style: Literal['pandas', 'polars_group', 'polars_over']
extra_codes=extra_codes,
**kwargs)

logger.info(f'code is generated')

if format:
# 格式化。在遗传算法中没有必要
codes = format_str(codes, mode=Mode(line_length=600, magic_trailing_comma=True))
Expand Down Expand Up @@ -301,6 +303,7 @@ def _get_code(self,

@lru_cache(maxsize=64, typed=True)
def _get_func_from_code(code: str):
logger.info(f'get func from code')
globals_ = {}
exec(code, globals_)
return globals_['main']
Expand All @@ -310,14 +313,14 @@ def _get_func_from_code(code: str):
def _get_func_from_module(module: str):
""""可下断点调试"""
m = __import__(module, fromlist=['*'])
logger.info(f'run module {m}')
logger.info(f'get func from module {m}')
return m.main


@lru_cache(maxsize=64, typed=True)
def _get_func_from_file(file: str):
file = pathlib.Path(file)
logger.info(f'run file "{file.absolute()}"')
logger.info(f'get func from file "{file.absolute()}"')
with open(file, 'r', encoding='utf-8') as f:
globals_ = {}
exec(f.read(), globals_)
Expand Down Expand Up @@ -378,8 +381,16 @@ def codegen_exec(df: Optional[DataFrame],
-------
DataFrame
Notes
-----
处处都有缓存,所以在公式研发阶段要留意日志输出。以免一直调试的旧公式
1. 确保重新生成了代码 `code is generated`
2. 通过代码得到了函数 `get func from code`
"""
if df is not None:
# 以下代码都带缓存功能
if run_file is True:
assert output_file is not None, 'output_file is required'
return _get_func_from_file(output_file)(df)
Expand Down Expand Up @@ -411,4 +422,5 @@ def codegen_exec(df: Optional[DataFrame],
if df is None:
return None
else:
# 代码一样时就从缓存中取出函数
return _get_func_from_code(code)(df)

0 comments on commit 53c2166

Please sign in to comment.