diff --git a/examples/demo_tdx.py b/examples/demo_tdx.py index ddd9598..d449968 100644 --- a/examples/demo_tdx.py +++ b/examples/demo_tdx.py @@ -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('计算结束') diff --git a/expr_codegen/_version.py b/expr_codegen/_version.py index f481583..47f57bf 100644 --- a/expr_codegen/_version.py +++ b/expr_codegen/_version.py @@ -1 +1 @@ -__version__ = "0.10.10" +__version__ = "0.10.11" diff --git a/expr_codegen/tool.py b/expr_codegen/tool.py index 2126d84..964a07e 100644 --- a/expr_codegen/tool.py +++ b/expr_codegen/tool.py @@ -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)) @@ -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'] @@ -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_) @@ -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) @@ -411,4 +422,5 @@ def codegen_exec(df: Optional[DataFrame], if df is None: return None else: + # 代码一样时就从缓存中取出函数 return _get_func_from_code(code)(df)