expr-codegen 0.10.9__tar.gz → 0.10.11__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.
Files changed (34) hide show
  1. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/PKG-INFO +2 -2
  2. expr_codegen-0.10.11/expr_codegen/_version.py +1 -0
  3. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/template.py.j2 +3 -3
  4. {expr_codegen-0.10.9/expr_codegen/polars_over → expr_codegen-0.10.11/expr_codegen/polars_group}/template.py.j2 +3 -3
  5. {expr_codegen-0.10.9/expr_codegen/polars_group → expr_codegen-0.10.11/expr_codegen/polars_over}/template.py.j2 +3 -3
  6. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/tool.py +35 -19
  7. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/PKG-INFO +2 -2
  8. expr_codegen-0.10.9/expr_codegen/_version.py +0 -1
  9. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/LICENSE +0 -0
  10. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/README.md +0 -0
  11. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/__init__.py +0 -0
  12. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/codes.py +0 -0
  13. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/dag.py +0 -0
  14. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/expr.py +0 -0
  15. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/latex/__init__.py +0 -0
  16. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/latex/printer.py +0 -0
  17. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/model.py +0 -0
  18. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/__init__.py +0 -0
  19. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/code.py +0 -0
  20. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/helper.py +0 -0
  21. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/printer.py +0 -0
  22. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/ta.py +0 -0
  23. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_group/__init__.py +0 -0
  24. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_group/code.py +0 -0
  25. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_group/printer.py +0 -0
  26. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_over/__init__.py +0 -0
  27. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_over/code.py +0 -0
  28. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_over/printer.py +0 -0
  29. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/SOURCES.txt +0 -0
  30. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/dependency_links.txt +0 -0
  31. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/requires.txt +0 -0
  32. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/top_level.txt +0 -0
  33. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/pyproject.toml +0 -0
  34. {expr_codegen-0.10.9 → expr_codegen-0.10.11}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: expr_codegen
3
- Version: 0.10.9
3
+ Version: 0.10.11
4
4
  Summary: symbol expression to polars expression tool
5
5
  Author-email: wukan <wu-kan@163.com>
6
6
  License: BSD 3-Clause License
@@ -0,0 +1 @@
1
+ __version__ = "0.10.11"
@@ -63,6 +63,6 @@ def main(df: pd.DataFrame) -> pd.DataFrame:
63
63
 
64
64
  return df
65
65
 
66
- if __name__ in ("__main__", "builtins"):
67
- # TODO: 数据加载或外部传入
68
- df_output = main(df_input)
66
+ # if __name__ in ("__main__", "builtins"):
67
+ # # TODO: 数据加载或外部传入
68
+ # df_output = main(df_input)
@@ -78,6 +78,6 @@ def main(df: DataFrame) -> DataFrame:
78
78
 
79
79
  return df
80
80
 
81
- if __name__ in ("__main__", "builtins"):
82
- # TODO: 数据加载或外部传入
83
- df_output = main(df_input)
81
+ # if __name__ in ("__main__", "builtins"):
82
+ # # TODO: 数据加载或外部传入
83
+ # df_output = main(df_input)
@@ -78,6 +78,6 @@ def main(df: DataFrame) -> DataFrame:
78
78
 
79
79
  return df
80
80
 
81
- if __name__ in ("__main__", "builtins"):
82
- # TODO: 数据加载或外部传入
83
- df_output = main(df_input)
81
+ # if __name__ in ("__main__", "builtins"):
82
+ # # TODO: 数据加载或外部传入
83
+ # df_output = main(df_input)
@@ -257,6 +257,8 @@ class ExprTool:
257
257
  extra_codes=extra_codes,
258
258
  **kwargs)
259
259
 
260
+ logger.info(f'code is generated')
261
+
260
262
  if format:
261
263
  # 格式化。在遗传算法中没有必要
262
264
  codes = format_str(codes, mode=Mode(line_length=600, magic_trailing_comma=True))
@@ -299,25 +301,30 @@ class ExprTool:
299
301
  return code
300
302
 
301
303
 
302
- def _exec_code(code: str, df_input):
303
- globals_ = {'df_input': df_input}
304
+ @lru_cache(maxsize=64, typed=True)
305
+ def _get_func_from_code(code: str):
306
+ logger.info(f'get func from code')
307
+ globals_ = {}
304
308
  exec(code, globals_)
305
- return globals_['df_output']
306
-
307
-
308
- def _exec_file(file, df_input):
309
- file = pathlib.Path(file)
310
- logger.info(f'run file "{file.absolute()}"')
311
- with open(file, 'r', encoding='utf-8') as f:
312
- code = f.read()
313
- return _exec_code(code, df_input)
309
+ return globals_['main']
314
310
 
315
311
 
316
- def _exec_module(module: str, df_input):
312
+ @lru_cache(maxsize=64, typed=True)
313
+ def _get_func_from_module(module: str):
317
314
  """"可下断点调试"""
318
315
  m = __import__(module, fromlist=['*'])
319
- logger.info(f'run module {m}')
320
- return m.main(df_input)
316
+ logger.info(f'get func from module {m}')
317
+ return m.main
318
+
319
+
320
+ @lru_cache(maxsize=64, typed=True)
321
+ def _get_func_from_file(file: str):
322
+ file = pathlib.Path(file)
323
+ logger.info(f'get func from file "{file.absolute()}"')
324
+ with open(file, 'r', encoding='utf-8') as f:
325
+ globals_ = {}
326
+ exec(f.read(), globals_)
327
+ return globals_['main']
321
328
 
322
329
 
323
330
  _TOOL_ = ExprTool()
@@ -347,7 +354,7 @@ def codegen_exec(df: Optional[DataFrame],
347
354
  output_file: str| TextIOBase
348
355
  保存生成的目标代码到文件中
349
356
  run_file: bool or str
350
- 是否不生成脚本,直接运行代码。
357
+ 是否不生成脚本,直接运行代码。注意:带缓存功能,多次调用不重复生成
351
358
  - 如果是True,会自动从output_file中读取代码
352
359
  - 如果是字符串,会自动从run_file中读取代码
353
360
  - 如果是模块名,会自动从模块中读取代码(可调试)
@@ -374,17 +381,25 @@ def codegen_exec(df: Optional[DataFrame],
374
381
  -------
375
382
  DataFrame
376
383
 
384
+ Notes
385
+ -----
386
+ 处处都有缓存,所以在公式研发阶段要留意日志输出。以免一直调试的旧公式
387
+
388
+ 1. 确保重新生成了代码 `code is generated`
389
+ 2. 通过代码得到了函数 `get func from code`
390
+
377
391
  """
378
392
  if df is not None:
393
+ # 以下代码都带缓存功能
379
394
  if run_file is True:
380
395
  assert output_file is not None, 'output_file is required'
381
- return _exec_file(output_file, df)
396
+ return _get_func_from_file(output_file)(df)
382
397
  if run_file is not False:
383
398
  run_file = str(run_file)
384
399
  if run_file.endswith('.py'):
385
- return _exec_file(run_file, df)
400
+ return _get_func_from_file(run_file)(df)
386
401
  else:
387
- return _exec_module(run_file, df) # 可断点调试
402
+ return _get_func_from_module(run_file)(df) # 可断点调试
388
403
 
389
404
  # 此代码来自于sympy.var
390
405
  frame = inspect.currentframe().f_back
@@ -407,4 +422,5 @@ def codegen_exec(df: Optional[DataFrame],
407
422
  if df is None:
408
423
  return None
409
424
  else:
410
- return _exec_code(code, df)
425
+ # 代码一样时就从缓存中取出函数
426
+ return _get_func_from_code(code)(df)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: expr_codegen
3
- Version: 0.10.9
3
+ Version: 0.10.11
4
4
  Summary: symbol expression to polars expression tool
5
5
  Author-email: wukan <wu-kan@163.com>
6
6
  License: BSD 3-Clause License
@@ -1 +0,0 @@
1
- __version__ = "0.10.9"
File without changes
File without changes
File without changes