expr-codegen 0.13.5__tar.gz → 0.14.0__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.13.5 → expr_codegen-0.14.0}/PKG-INFO +1 -1
- expr_codegen-0.14.0/expr_codegen/_version.py +1 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/pandas/code.py +9 -9
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/pandas/template.py.j2 +6 -3
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/polars/code.py +9 -9
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/polars/template.py.j2 +6 -3
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/tool.py +3 -3
- expr_codegen-0.13.5/expr_codegen/_version.py +0 -1
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/.gitignore +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/LICENSE +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/README.md +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/__init__.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/codes.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/dag.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/expr.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/latex/__init__.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/latex/printer.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/model.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/pandas/__init__.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/pandas/helper.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/pandas/printer.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/pandas/ta.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/polars/__init__.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/polars/printer.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/sql/__init__.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/sql/code.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/sql/printer.py +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/expr_codegen/sql/template.sql.j2 +0 -0
- {expr_codegen-0.13.5 → expr_codegen-0.14.0}/pyproject.toml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.14.0"
|
|
@@ -95,15 +95,15 @@ def codegen(exprs_ldl: ListDictList, exprs_src, syms_dst,
|
|
|
95
95
|
|
|
96
96
|
syms1 = symbols_to_code(syms_dst)
|
|
97
97
|
syms2 = symbols_to_code(syms_out)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
98
|
+
# filter_last处理
|
|
99
|
+
_groupbys = {'sort': groupbys['sort']}
|
|
100
|
+
if ts_func_name is None:
|
|
101
|
+
_groupbys['_filter_last'] = "df = _filter_last(df.sort_values(by=[_DATE_]), filter_last)"
|
|
102
|
+
for k, v in groupbys.items():
|
|
103
|
+
_groupbys[k] = v
|
|
104
|
+
if k == ts_func_name:
|
|
105
|
+
_groupbys[k + '_filter_last'] = "df = _filter_last(df, filter_last)"
|
|
106
|
+
groupbys = _groupbys
|
|
107
107
|
|
|
108
108
|
try:
|
|
109
109
|
env = jinja2.Environment(loader=FileSystemLoader(os.path.dirname(__file__)))
|
|
@@ -51,12 +51,15 @@ def {{ key }}(df: pd.DataFrame) -> pd.DataFrame:
|
|
|
51
51
|
"""
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
def
|
|
54
|
+
def _filter_last(df: pd.DataFrame, filter_last: bool) -> pd.DataFrame:
|
|
55
55
|
"""过滤数据,只取最后一天。实盘时可用于减少计算量"""
|
|
56
|
-
|
|
56
|
+
if filter_last:
|
|
57
|
+
return df[df[_DATE_] >= df[_DATE_].iloc[-1]]
|
|
58
|
+
else:
|
|
59
|
+
return df
|
|
57
60
|
|
|
58
61
|
|
|
59
|
-
def main(df: pd.DataFrame) -> pd.DataFrame:
|
|
62
|
+
def main(df: pd.DataFrame, filter_last: bool) -> pd.DataFrame:
|
|
60
63
|
{% for key, value in groupbys.items() %}
|
|
61
64
|
{{ value-}}
|
|
62
65
|
{% endfor %}
|
|
@@ -120,15 +120,15 @@ def codegen(exprs_ldl: ListDictList, exprs_src, syms_dst,
|
|
|
120
120
|
|
|
121
121
|
syms1 = symbols_to_code(syms_dst)
|
|
122
122
|
syms2 = symbols_to_code(syms_out)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
# filter_last处理
|
|
124
|
+
_groupbys = {'sort': groupbys['sort']}
|
|
125
|
+
if ts_func_name is None:
|
|
126
|
+
_groupbys['_filter_last'] = "df = _filter_last(df.sort(_DATE_), filter_last)"
|
|
127
|
+
for k, v in groupbys.items():
|
|
128
|
+
_groupbys[k] = v
|
|
129
|
+
if k == ts_func_name:
|
|
130
|
+
_groupbys[k + '_filter_last'] = "df = _filter_last(df, filter_last)"
|
|
131
|
+
groupbys = _groupbys
|
|
132
132
|
|
|
133
133
|
try:
|
|
134
134
|
env = jinja2.Environment(loader=FileSystemLoader(os.path.dirname(__file__)))
|
|
@@ -62,17 +62,20 @@ def {{ key }}(df: DataFrame) -> DataFrame:
|
|
|
62
62
|
"""
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
def
|
|
65
|
+
def _filter_last(df: DataFrame, filter_last: bool) -> DataFrame:
|
|
66
66
|
"""过滤数据,只取最后一天。实盘时可用于减少计算量
|
|
67
67
|
前一个调用的ts,这里可以直接调用,可以认为已经排序好
|
|
68
68
|
`df = filter_last(df)`
|
|
69
69
|
反之
|
|
70
70
|
`df = filter_last(df.sort(_DATE_))`
|
|
71
71
|
"""
|
|
72
|
-
|
|
72
|
+
if filter_last:
|
|
73
|
+
return df.filter(pl.col(_DATE_) >= df.select(pl.last(_DATE_))[0, 0])
|
|
74
|
+
else:
|
|
75
|
+
return df
|
|
73
76
|
|
|
74
77
|
|
|
75
|
-
def main(df: DataFrame) -> DataFrame:
|
|
78
|
+
def main(df: DataFrame, filter_last: bool) -> DataFrame:
|
|
76
79
|
{% for key, value in groupbys.items() %}
|
|
77
80
|
{{ value-}}
|
|
78
81
|
{% endfor %}
|
|
@@ -451,12 +451,12 @@ def codegen_exec(df: Union[DataFrame, None],
|
|
|
451
451
|
|
|
452
452
|
if input_file is not None:
|
|
453
453
|
if input_file.endswith('.py'):
|
|
454
|
-
return _get_func_from_file_py(input_file)(df)
|
|
454
|
+
return _get_func_from_file_py(input_file)(df, filter_last)
|
|
455
455
|
elif input_file.endswith('.sql'):
|
|
456
456
|
with pl.SQLContext(frames={table_name: df}) as ctx:
|
|
457
457
|
return ctx.execute(_get_code_from_file(input_file), eager=isinstance(df, _pl_DataFrame))
|
|
458
458
|
else:
|
|
459
|
-
return _get_func_from_module(input_file)(df) # 可断点调试
|
|
459
|
+
return _get_func_from_module(input_file)(df, filter_last) # 可断点调试
|
|
460
460
|
else:
|
|
461
461
|
pass
|
|
462
462
|
|
|
@@ -489,4 +489,4 @@ def codegen_exec(df: Union[DataFrame, None],
|
|
|
489
489
|
return ctx.execute(code, eager=isinstance(df, _pl_DataFrame))
|
|
490
490
|
else:
|
|
491
491
|
# 代码一样时就从缓存中取出函数
|
|
492
|
-
return _get_func_from_code_py(code)(df)
|
|
492
|
+
return _get_func_from_code_py(code)(df, filter_last)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.13.5"
|
|
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
|