expr-codegen 0.6.0__tar.gz → 0.6.2__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 (28) hide show
  1. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/PKG-INFO +1 -1
  2. expr_codegen-0.6.2/expr_codegen/_version.py +1 -0
  3. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/codes.py +25 -7
  4. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/expr.py +1 -1
  5. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/pandas/template.py.j2 +2 -1
  6. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/polars/template.py.j2 +2 -1
  7. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen.egg-info/PKG-INFO +1 -1
  8. expr_codegen-0.6.0/expr_codegen/_version.py +0 -1
  9. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/LICENSE +0 -0
  10. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/README.md +0 -0
  11. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/__init__.py +0 -0
  12. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/dag.py +0 -0
  13. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/latex/__init__.py +0 -0
  14. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/latex/printer.py +0 -0
  15. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/model.py +0 -0
  16. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/pandas/__init__.py +0 -0
  17. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/pandas/code.py +0 -0
  18. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/pandas/printer.py +0 -0
  19. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/polars/__init__.py +0 -0
  20. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/polars/code.py +0 -0
  21. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/polars/printer.py +0 -0
  22. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen/tool.py +0 -0
  23. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen.egg-info/SOURCES.txt +0 -0
  24. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen.egg-info/dependency_links.txt +0 -0
  25. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen.egg-info/requires.txt +0 -0
  26. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/expr_codegen.egg-info/top_level.txt +0 -0
  27. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/pyproject.toml +0 -0
  28. {expr_codegen-0.6.0 → expr_codegen-0.6.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: expr_codegen
3
- Version: 0.6.0
3
+ Version: 0.6.2
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.6.2"
@@ -1,5 +1,6 @@
1
1
  import ast
2
2
  import re
3
+ from ast import expr
3
4
 
4
5
  from sympy import Add, Mul, Pow, Eq
5
6
 
@@ -21,7 +22,7 @@ class SympyTransformer(ast.NodeTransformer):
21
22
  # 映射
22
23
  funcs_map = {}
23
24
  args_map = {}
24
- targets_map = {}
25
+ targets_map = {} # 只对非下划线开头的生效
25
26
 
26
27
  def config_map(self, funcs_map, args_map, targets_map):
27
28
  self.funcs_map = funcs_map
@@ -43,18 +44,35 @@ class SympyTransformer(ast.NodeTransformer):
43
44
  self.generic_visit(node)
44
45
  return node
45
46
 
47
+ def __visit_Assign(self, target: expr):
48
+ old_target_id = target.id
49
+ new_target_id = self.targets_map.get(old_target_id, old_target_id)
50
+ self.targets_old.add(old_target_id)
51
+
52
+ # 赋值给下划线开头代码时,对其进行重命名,方便重复书写表达式时不冲突
53
+ if old_target_id.startswith('_'):
54
+ new_target_id = f'{old_target_id}_{len(self.targets_new):03d}'
55
+
56
+ if old_target_id != new_target_id:
57
+ self.targets_new.add(new_target_id)
58
+ target.id = new_target_id
59
+ # 记录修改的变量名,之后会使用到
60
+ self.args_map[old_target_id] = new_target_id
61
+
46
62
  def visit_Assign(self, node):
47
63
  # 提取输出变量名
48
64
  for target in node.targets:
49
65
  if isinstance(target, ast.Tuple):
50
66
  for t in target.elts:
51
- self.targets_old.add(t.id)
52
- t.id = self.targets_map.get(t.id, t.id)
53
- self.targets_new.add(t.id)
67
+ self.__visit_Assign(t)
54
68
  else:
55
- self.targets_old.add(target.id)
56
- target.id = self.targets_map.get(target.id, target.id)
57
- self.targets_new.add(target.id)
69
+ self.__visit_Assign(target)
70
+
71
+ # 处理 alpha=close 这种情况
72
+ if isinstance(node.value, ast.Name):
73
+ self.args_old.add(node.value.id)
74
+ node.value.id = self.args_map.get(node.value.id, node.value.id)
75
+ self.args_new.add(node.value.id)
58
76
 
59
77
  self.generic_visit(node)
60
78
  return node
@@ -352,7 +352,7 @@ def _replace__repeat(e):
352
352
  node_name = get_node_name(node)
353
353
  node_args0_name = get_node_name(node.args[0])
354
354
  if node_name == node_args0_name:
355
- if node.name in ('cs_rank', 'sign', 'Abs'):
355
+ if node.name in ('cs_rank', 'sign', 'Abs', 'abs_'):
356
356
  replacements.append((node, node.args[0]))
357
357
  for node, replacement in replacements:
358
358
  print(node, ' -> ', replacement)
@@ -56,7 +56,8 @@ def main(df: pd.DataFrame) -> pd.DataFrame:
56
56
  {% endfor %}
57
57
 
58
58
  # drop intermediate columns
59
- df = df.drop(columns=list(filter(lambda x: re.search(r"^_x_\d+", x), df.columns)))
59
+ # df = df.drop(columns=list(filter(lambda x: re.search(r"^_x_\d+", x), df.columns)))
60
+ df = df.drop(columns=list(filter(lambda x: x.startswith("_"), df.columns)))
60
61
 
61
62
  # logger.info('done')
62
63
 
@@ -58,7 +58,8 @@ def main(df: pl.DataFrame) -> pl.DataFrame:
58
58
  {% endfor %}
59
59
 
60
60
  # drop intermediate columns
61
- df = df.select(pl.exclude(r'^_x_\d+$'))
61
+ # df = df.select(pl.exclude(r'^_x_\d+$'))
62
+ df = df.select(~cs.starts_with("_"))
62
63
 
63
64
  # shrink
64
65
  df = df.select(cs.all().shrink_dtype())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: expr_codegen
3
- Version: 0.6.0
3
+ Version: 0.6.2
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.6.0"
File without changes
File without changes
File without changes