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.
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/PKG-INFO +2 -2
- expr_codegen-0.10.11/expr_codegen/_version.py +1 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/template.py.j2 +3 -3
- {expr_codegen-0.10.9/expr_codegen/polars_over → expr_codegen-0.10.11/expr_codegen/polars_group}/template.py.j2 +3 -3
- {expr_codegen-0.10.9/expr_codegen/polars_group → expr_codegen-0.10.11/expr_codegen/polars_over}/template.py.j2 +3 -3
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/tool.py +35 -19
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/PKG-INFO +2 -2
- expr_codegen-0.10.9/expr_codegen/_version.py +0 -1
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/LICENSE +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/README.md +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/__init__.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/codes.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/dag.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/expr.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/latex/__init__.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/latex/printer.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/model.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/__init__.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/code.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/helper.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/printer.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/pandas/ta.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_group/__init__.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_group/code.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_group/printer.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_over/__init__.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_over/code.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen/polars_over/printer.py +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/SOURCES.txt +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/dependency_links.txt +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/requires.txt +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/expr_codegen.egg-info/top_level.txt +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/pyproject.toml +0 -0
- {expr_codegen-0.10.9 → expr_codegen-0.10.11}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.10.11"
|
|
@@ -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
|
-
|
|
303
|
-
|
|
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_['
|
|
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
|
-
|
|
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'
|
|
320
|
-
return m.main
|
|
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
|
|
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
|
|
400
|
+
return _get_func_from_file(run_file)(df)
|
|
386
401
|
else:
|
|
387
|
-
return
|
|
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
|
-
|
|
425
|
+
# 代码一样时就从缓存中取出函数
|
|
426
|
+
return _get_func_from_code(code)(df)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.10.9"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|