expr-codegen 0.13.4__tar.gz → 0.13.5__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 (29) hide show
  1. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/PKG-INFO +1 -1
  2. expr_codegen-0.13.5/expr_codegen/_version.py +1 -0
  3. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/tool.py +17 -5
  4. expr_codegen-0.13.4/expr_codegen/_version.py +0 -1
  5. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/.gitignore +0 -0
  6. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/LICENSE +0 -0
  7. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/README.md +0 -0
  8. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/__init__.py +0 -0
  9. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/codes.py +0 -0
  10. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/dag.py +0 -0
  11. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/expr.py +0 -0
  12. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/latex/__init__.py +0 -0
  13. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/latex/printer.py +0 -0
  14. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/model.py +0 -0
  15. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/pandas/__init__.py +0 -0
  16. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/pandas/code.py +0 -0
  17. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/pandas/helper.py +0 -0
  18. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/pandas/printer.py +0 -0
  19. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/pandas/ta.py +0 -0
  20. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/pandas/template.py.j2 +0 -0
  21. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/polars/__init__.py +0 -0
  22. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/polars/code.py +0 -0
  23. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/polars/printer.py +0 -0
  24. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/polars/template.py.j2 +0 -0
  25. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/sql/__init__.py +0 -0
  26. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/sql/code.py +0 -0
  27. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/sql/printer.py +0 -0
  28. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/expr_codegen/sql/template.sql.j2 +0 -0
  29. {expr_codegen-0.13.4 → expr_codegen-0.13.5}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: expr_codegen
3
- Version: 0.13.4
3
+ Version: 0.13.5
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.13.5"
@@ -10,6 +10,7 @@ from loguru import logger
10
10
  from sympy import simplify, cse, symbols, numbered_symbols
11
11
  from sympy.core.expr import Expr
12
12
  from sympy.logic import boolalg
13
+ from sympy.simplify import cse_opts
13
14
 
14
15
  from expr_codegen.codes import sources_to_exprs
15
16
  from expr_codegen.expr import get_current_by_prefix, get_children, replace_exprs
@@ -48,7 +49,10 @@ Expr.diff = _diff
48
49
 
49
50
  # ===============================
50
51
 
51
- def simplify2(expr):
52
+ def simplify2(expr, skip_simplify: bool):
53
+ # OPEN/OPEN会被简化成1,遗传算法中常出现,可以跳过简化
54
+ if skip_simplify:
55
+ return expr
52
56
  try:
53
57
  expr = simplify(expr)
54
58
  except (AttributeError, TypeError) as e:
@@ -92,7 +96,7 @@ class ExprTool:
92
96
  # print(exprs)
93
97
  return exprs, syms
94
98
 
95
- def merge(self, date, asset, args):
99
+ def merge(self, date, asset, args, skip_simplify):
96
100
  """合并多个表达式
97
101
 
98
102
  1. 先抽取分割子公式
@@ -108,7 +112,7 @@ class ExprTool:
108
112
  表达式列表
109
113
  """
110
114
  # 抽取前先化简
111
- args = [(k, simplify2(v), c) for k, v, c in args]
115
+ args = [(k, simplify2(v, skip_simplify), c) for k, v, c in args]
112
116
 
113
117
  # 保留了注释信息
114
118
  exprs_syms = [(self.extract(v, date, asset), c) for k, v, c in args]
@@ -171,7 +175,7 @@ class ExprTool:
171
175
  _exprs = [k for k, v in exprs]
172
176
 
173
177
  # 注意:对于表达式右边相同,左边不同的情况,会当成一个处理
174
- repl, redu = cse(_exprs, symbols_repl, optimizations="basic")
178
+ repl, redu = cse(_exprs, symbols_repl, optimizations=[(cse_opts.sub_pre, cse_opts.sub_post), ])
175
179
  outputs_len = len(exprs_src)
176
180
 
177
181
  new_redu = []
@@ -204,6 +208,7 @@ class ExprTool:
204
208
  over_null: Literal['order_by', 'partition_by', None] = 'partition_by',
205
209
  table_name: str = 'self',
206
210
  filter_last: bool = False,
211
+ skip_simplify: bool = False,
207
212
  **kwargs):
208
213
  """功能集成版,将几个功能写到一起方便使用
209
214
 
@@ -229,6 +234,7 @@ class ExprTool:
229
234
  需要复制到模板中的额外代码
230
235
  table_name
231
236
  filter_last
237
+ skip_simplify
232
238
 
233
239
  Returns
234
240
  -------
@@ -241,7 +247,7 @@ class ExprTool:
241
247
  exprs_src = replace_exprs(exprs_src)
242
248
 
243
249
  # 子表达式在前,原表式在最后
244
- exprs_dst, syms_dst = self.merge(date, asset, exprs_src)
250
+ exprs_dst, syms_dst = self.merge(date, asset, exprs_src, skip_simplify)
245
251
  syms_dst = list(set(syms_dst) - _RESERVED_WORD_)
246
252
 
247
253
  # 提取公共表达式
@@ -292,6 +298,7 @@ class ExprTool:
292
298
  over_null: Literal['order_by', 'partition_by', None] = 'partition_by',
293
299
  table_name: str = 'self',
294
300
  filter_last: bool = False,
301
+ skip_simplify: bool = False,
295
302
  **kwargs) -> str:
296
303
  """通过字符串生成代码, 加了缓存,多次调用不重复生成"""
297
304
  raw, exprs_list = sources_to_exprs(self.globals_, source, *more_sources, convert_xor=convert_xor)
@@ -308,6 +315,7 @@ class ExprTool:
308
315
  over_null=over_null,
309
316
  table_name=table_name,
310
317
  filter_last=filter_last,
318
+ skip_simplify=skip_simplify,
311
319
  **kwargs)
312
320
 
313
321
  # 移回到cache,防止多次调用多次保存
@@ -371,6 +379,7 @@ def codegen_exec(df: Union[DataFrame, None],
371
379
  date: str = 'date', asset: str = 'asset',
372
380
  table_name: str = 'self',
373
381
  filter_last: bool = False,
382
+ skip_simplify: bool = False,
374
383
  **kwargs) -> Union[DataFrame, str]:
375
384
  """快速转换源代码并执行
376
385
 
@@ -412,6 +421,8 @@ def codegen_exec(df: Union[DataFrame, None],
412
421
  表名。只在style参数为sql时有效
413
422
  filter_last:bool
414
423
  在实盘时,只需要最后一天日期的数据,可以在最后一个`ts`之后过滤数据。目前只在style参数为'polars', 'pandas'时有效
424
+ skip_simplify:bool
425
+ 遗传算法时很有可能出现OPEN/OPEN,可以跳过化简步骤
415
426
 
416
427
 
417
428
  Returns
@@ -466,6 +477,7 @@ def codegen_exec(df: Union[DataFrame, None],
466
477
  over_null=over_null,
467
478
  table_name=table_name,
468
479
  filter_last=filter_last,
480
+ skip_simplify=skip_simplify,
469
481
  **kwargs
470
482
  )
471
483
 
@@ -1 +0,0 @@
1
- __version__ = "0.13.4"
File without changes
File without changes
File without changes