expr-codegen 0.7.2__tar.gz → 0.7.3__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.7.2 → expr_codegen-0.7.3}/PKG-INFO +1 -1
- expr_codegen-0.7.3/expr_codegen/_version.py +1 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/pandas/code.py +7 -3
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/polars/code.py +9 -7
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/polars/template.py.j2 +1 -2
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen.egg-info/PKG-INFO +1 -1
- expr_codegen-0.7.2/expr_codegen/_version.py +0 -1
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/LICENSE +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/README.md +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/__init__.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/codes.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/dag.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/expr.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/latex/__init__.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/latex/printer.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/model.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/pandas/__init__.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/pandas/printer.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/pandas/template.py.j2 +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/polars/__init__.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/polars/printer.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen/tool.py +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen.egg-info/SOURCES.txt +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen.egg-info/dependency_links.txt +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen.egg-info/requires.txt +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/expr_codegen.egg-info/top_level.txt +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/pyproject.toml +0 -0
- {expr_codegen-0.7.2 → expr_codegen-0.7.3}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.7.3"
|
|
@@ -29,7 +29,7 @@ def get_groupby_from_tuple(tup, func_name):
|
|
|
29
29
|
|
|
30
30
|
def symbols_to_code(syms, alias):
|
|
31
31
|
a = [f"{s}" for s in syms]
|
|
32
|
-
b = [f"
|
|
32
|
+
b = [f"'{alias.get(s, s)}'" for s in syms]
|
|
33
33
|
return f"""_ = ({','.join(b)},)
|
|
34
34
|
({','.join(a)},) = _"""
|
|
35
35
|
|
|
@@ -46,7 +46,7 @@ def codegen(exprs_ldl: ListDictList, exprs_src, syms_dst,
|
|
|
46
46
|
# polars风格代码
|
|
47
47
|
funcs = {}
|
|
48
48
|
# 分组应用代码。这里利用了字典按插入顺序排序的特点,将排序放在最前
|
|
49
|
-
groupbys = {'sort': '
|
|
49
|
+
groupbys = {'sort': ''}
|
|
50
50
|
# 处理过后的表达式
|
|
51
51
|
exprs_dst = []
|
|
52
52
|
syms_out = []
|
|
@@ -70,9 +70,13 @@ def codegen(exprs_ldl: ListDictList, exprs_src, syms_dst,
|
|
|
70
70
|
syms_out.append(va)
|
|
71
71
|
|
|
72
72
|
if k[0] == TS:
|
|
73
|
-
groupbys['sort']
|
|
73
|
+
if len(groupbys['sort']) == 0:
|
|
74
|
+
groupbys['sort'] = f'df = df.sort_values(by=[_ASSET_, _DATE_]).reset_index(drop=True)'
|
|
74
75
|
# 时序需要排序
|
|
75
76
|
func_code = [f' df = df.sort_values(by=[_DATE_])'] + func_code
|
|
77
|
+
elif k[0] == CS:
|
|
78
|
+
if len(groupbys['sort']) == 0:
|
|
79
|
+
groupbys['sort'] = f'df = df.sort_values(by=[_DATE_, _ASSET_]).reset_index(drop=True)'
|
|
76
80
|
|
|
77
81
|
# polars风格代码列表
|
|
78
82
|
funcs[func_name] = '\n'.join(func_code)
|
|
@@ -16,20 +16,21 @@ def get_groupby_from_tuple(tup, func_name):
|
|
|
16
16
|
if prefix2 == TS:
|
|
17
17
|
# 组内需要按时间进行排序,需要维持顺序
|
|
18
18
|
prefix2, asset = tup
|
|
19
|
-
return f'df = df.group_by(_ASSET_).map_groups({func_name})'
|
|
19
|
+
return f'df = df.sort(_ASSET_, _DATE_).group_by(_ASSET_).map_groups({func_name})'
|
|
20
20
|
if prefix2 == CS:
|
|
21
21
|
prefix2, date = tup
|
|
22
|
-
return f'df = df.group_by(_DATE_).map_groups({func_name})'
|
|
22
|
+
return f'df = df.sort(_DATE_).group_by(_DATE_).map_groups({func_name})'
|
|
23
23
|
if prefix2 == GP:
|
|
24
24
|
prefix2, date, group = tup
|
|
25
|
-
return f'df = df.group_by(_DATE_, "{group}").map_groups({func_name})'
|
|
25
|
+
return f'df = df.sort(_DATE_, "{group}").group_by(_DATE_, "{group}").map_groups({func_name})'
|
|
26
26
|
|
|
27
27
|
return f'df = {func_name}(df)'
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
def symbols_to_code(syms, alias):
|
|
31
31
|
a = [f"{s}" for s in syms]
|
|
32
|
-
b = [f"r'{alias.get(s, s)}'" for s in syms]
|
|
32
|
+
b = [f"r'{alias.get(s, s)}'" for s in syms] #
|
|
33
|
+
b = [f"'{alias.get(s, s)}'" for s in syms]
|
|
33
34
|
return f"""_ = ({','.join(b)},)
|
|
34
35
|
({','.join(a)},) = (pl.col(i) for i in _)"""
|
|
35
36
|
|
|
@@ -46,7 +47,7 @@ def codegen(exprs_ldl: ListDictList, exprs_src, syms_dst,
|
|
|
46
47
|
# polars风格代码
|
|
47
48
|
funcs = {}
|
|
48
49
|
# 分组应用代码。这里利用了字典按插入顺序排序的特点,将排序放在最前
|
|
49
|
-
groupbys = {'sort': '
|
|
50
|
+
groupbys = {'sort': ''}
|
|
50
51
|
# 处理过后的表达式
|
|
51
52
|
exprs_dst = []
|
|
52
53
|
syms_out = []
|
|
@@ -80,9 +81,10 @@ def codegen(exprs_ldl: ListDictList, exprs_src, syms_dst,
|
|
|
80
81
|
func_code = func_code[1:]
|
|
81
82
|
|
|
82
83
|
if k[0] == TS:
|
|
83
|
-
groupbys['sort']
|
|
84
|
+
# if len(groupbys['sort']) == 0:
|
|
85
|
+
# groupbys['sort'] = f'df = df.sort(_ASSET_, _DATE_)'
|
|
84
86
|
# 时序需要排序
|
|
85
|
-
func_code = [f' df = df.sort(
|
|
87
|
+
func_code = [f' df = df.sort(_DATE_)'] + func_code
|
|
86
88
|
|
|
87
89
|
# polars风格代码列表
|
|
88
90
|
funcs[func_name] = '\n'.join(func_code)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# this code is auto generated by the expr_codegen
|
|
2
2
|
# https://github.com/wukan1986/expr_codegen
|
|
3
3
|
# 此段代码由 expr_codegen 自动生成,欢迎提交 issue 或 pull request
|
|
4
|
-
import re
|
|
5
4
|
|
|
6
5
|
import numpy as np # noqa
|
|
7
6
|
import pandas as pd # noqa
|
|
@@ -68,7 +67,7 @@ def main(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
68
67
|
# logger.info('done')
|
|
69
68
|
|
|
70
69
|
# save
|
|
71
|
-
# df.write_parquet('output.parquet'
|
|
70
|
+
# df.write_parquet('output.parquet')
|
|
72
71
|
|
|
73
72
|
return df
|
|
74
73
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.7.2"
|
|
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
|