pylegend 0.7.0__py3-none-any.whl → 0.9.0__py3-none-any.whl

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 (35) hide show
  1. pylegend/_typing.py +6 -0
  2. pylegend/core/database/sql_to_string/db_extension.py +35 -6
  3. pylegend/core/language/pandas_api/__init__.py +13 -0
  4. pylegend/core/language/pandas_api/pandas_api_aggregate_specification.py +54 -0
  5. pylegend/core/language/pandas_api/pandas_api_custom_expressions.py +85 -0
  6. pylegend/core/language/pandas_api/pandas_api_series.py +174 -0
  7. pylegend/core/language/pandas_api/pandas_api_tds_row.py +74 -0
  8. pylegend/core/language/shared/literal_expressions.py +2 -2
  9. pylegend/core/language/shared/operations/integer_operation_expressions.py +35 -0
  10. pylegend/core/language/shared/operations/nary_expression.py +104 -0
  11. pylegend/core/language/shared/operations/primitive_operation_expressions.py +30 -0
  12. pylegend/core/language/shared/operations/string_operation_expressions.py +624 -1
  13. pylegend/core/language/shared/pct_helpers.py +56 -0
  14. pylegend/core/language/shared/primitives/integer.py +6 -0
  15. pylegend/core/language/shared/primitives/primitive.py +6 -0
  16. pylegend/core/language/shared/primitives/string.py +129 -1
  17. pylegend/core/sql/metamodel.py +3 -1
  18. pylegend/core/sql/metamodel_extension.py +18 -0
  19. pylegend/core/tds/pandas_api/frames/functions/aggregate_function.py +316 -0
  20. pylegend/core/tds/pandas_api/frames/functions/assign_function.py +20 -15
  21. pylegend/core/tds/pandas_api/frames/functions/drop.py +171 -0
  22. pylegend/core/tds/pandas_api/frames/functions/filter.py +193 -0
  23. pylegend/core/tds/pandas_api/frames/functions/filtering.py +85 -0
  24. pylegend/core/tds/pandas_api/frames/functions/sort_values_function.py +189 -0
  25. pylegend/core/tds/pandas_api/frames/functions/truncate_function.py +120 -0
  26. pylegend/core/tds/pandas_api/frames/pandas_api_applied_function_tds_frame.py +5 -1
  27. pylegend/core/tds/pandas_api/frames/pandas_api_base_tds_frame.py +204 -7
  28. pylegend/core/tds/pandas_api/frames/pandas_api_input_tds_frame.py +5 -3
  29. pylegend/core/tds/pandas_api/frames/pandas_api_tds_frame.py +90 -3
  30. {pylegend-0.7.0.dist-info → pylegend-0.9.0.dist-info}/METADATA +1 -1
  31. {pylegend-0.7.0.dist-info → pylegend-0.9.0.dist-info}/RECORD +35 -22
  32. {pylegend-0.7.0.dist-info → pylegend-0.9.0.dist-info}/WHEEL +0 -0
  33. {pylegend-0.7.0.dist-info → pylegend-0.9.0.dist-info}/licenses/LICENSE +0 -0
  34. {pylegend-0.7.0.dist-info → pylegend-0.9.0.dist-info}/licenses/LICENSE.spdx +0 -0
  35. {pylegend-0.7.0.dist-info → pylegend-0.9.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,104 @@
1
+ # Copyright 2025 Goldman Sachs
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from abc import ABCMeta
16
+ from pylegend._typing import (
17
+ PyLegendSequence,
18
+ PyLegendDict,
19
+ PyLegendCallable,
20
+ PyLegendList,
21
+ PyLegendOptional
22
+ )
23
+ from pylegend.core.language.shared.expression import (
24
+ PyLegendExpression,
25
+ )
26
+ from pylegend.core.language.shared.helpers import expr_has_matching_start_and_end_parentheses
27
+ from pylegend.core.sql.metamodel import (
28
+ Expression,
29
+ QuerySpecification,
30
+ )
31
+ from pylegend.core.tds.tds_frame import FrameToSqlConfig
32
+ from pylegend.core.tds.tds_frame import FrameToPureConfig
33
+
34
+ __all__: PyLegendSequence[str] = [
35
+ "PyLegendNaryExpression"
36
+ ]
37
+
38
+
39
+ class PyLegendNaryExpression(PyLegendExpression, metaclass=ABCMeta):
40
+ __operands: PyLegendList[PyLegendExpression]
41
+ __to_sql_func: PyLegendCallable[
42
+ [PyLegendList[Expression], PyLegendDict[str, QuerySpecification], FrameToSqlConfig],
43
+ Expression
44
+ ]
45
+ __to_pure_func: PyLegendCallable[
46
+ [PyLegendList[str], FrameToPureConfig],
47
+ str
48
+ ]
49
+ __non_nullable: bool
50
+ __operands_non_nullable_flags: PyLegendList[bool]
51
+
52
+ def __init__(
53
+ self,
54
+ operands: PyLegendList[PyLegendExpression],
55
+ to_sql_func: PyLegendCallable[
56
+ [PyLegendList[Expression], PyLegendDict[str, QuerySpecification], FrameToSqlConfig],
57
+ Expression
58
+ ],
59
+ to_pure_func: PyLegendCallable[
60
+ [PyLegendList[str], FrameToPureConfig],
61
+ str
62
+ ],
63
+ non_nullable: bool = False,
64
+ operands_non_nullable_flags: PyLegendOptional[PyLegendList[bool]] = None
65
+ ) -> None:
66
+ self.__operands = operands
67
+ self.__to_sql_func = to_sql_func
68
+ self.__to_pure_func = to_pure_func
69
+ self.__non_nullable = non_nullable
70
+ self.__operands_non_nullable_flags = (
71
+ operands_non_nullable_flags
72
+ if operands_non_nullable_flags is not None
73
+ else [False] * len(operands)
74
+ )
75
+
76
+ def to_sql_expression(
77
+ self,
78
+ frame_name_to_base_query_map: PyLegendDict[str, QuerySpecification],
79
+ config: FrameToSqlConfig
80
+ ) -> Expression:
81
+ sql_operands = [
82
+ operand.to_sql_expression(frame_name_to_base_query_map, config)
83
+ for operand in self.__operands
84
+ ]
85
+ return self.__to_sql_func(sql_operands, frame_name_to_base_query_map, config)
86
+
87
+ def to_pure_expression(self, config: FrameToPureConfig) -> str:
88
+ pure_operands: PyLegendList[str] = []
89
+
90
+ for operand, must_be_non_nullable in zip(self.__operands, self.__operands_non_nullable_flags):
91
+ expr = operand.to_pure_expression(config)
92
+
93
+ if must_be_non_nullable:
94
+ expr = (
95
+ expr if operand.is_non_nullable() else
96
+ f"toOne({expr[1:-1] if expr_has_matching_start_and_end_parentheses(expr) else expr})"
97
+ )
98
+
99
+ pure_operands.append(expr)
100
+
101
+ return self.__to_pure_func(pure_operands, config)
102
+
103
+ def is_non_nullable(self) -> bool:
104
+ return self.__non_nullable
@@ -19,6 +19,7 @@ from pylegend._typing import (
19
19
  from pylegend.core.language.shared.expression import (
20
20
  PyLegendExpression,
21
21
  PyLegendExpressionBooleanReturn,
22
+ PyLegendExpressionStringReturn
22
23
  )
23
24
  from pylegend.core.language.shared.helpers import generate_pure_functional_call
24
25
  from pylegend.core.language.shared.operations.binary_expression import PyLegendBinaryExpression
@@ -30,6 +31,8 @@ from pylegend.core.sql.metamodel import (
30
31
  ComparisonOperator,
31
32
  IsNullPredicate,
32
33
  IsNotNullPredicate,
34
+ Cast,
35
+ ColumnType
33
36
  )
34
37
  from pylegend.core.tds.tds_frame import FrameToSqlConfig
35
38
  from pylegend.core.tds.tds_frame import FrameToPureConfig
@@ -40,6 +43,7 @@ __all__: PyLegendSequence[str] = [
40
43
  "PyLegendPrimitiveNotEqualsExpression",
41
44
  "PyLegendIsEmptyExpression",
42
45
  "PyLegendIsNotEmptyExpression",
46
+ "PyLegendPrimitiveToStringExpression"
43
47
  ]
44
48
 
45
49
 
@@ -145,3 +149,29 @@ class PyLegendIsNotEmptyExpression(PyLegendUnaryExpression, PyLegendExpressionBo
145
149
  PyLegendIsNotEmptyExpression.__to_pure_func,
146
150
  non_nullable=True,
147
151
  )
152
+
153
+
154
+ class PyLegendPrimitiveToStringExpression(PyLegendUnaryExpression, PyLegendExpressionStringReturn):
155
+
156
+ @staticmethod
157
+ def __to_sql_func(
158
+ expression: Expression,
159
+ frame_name_to_base_query_map: PyLegendDict[str, QuerySpecification],
160
+ config: FrameToSqlConfig
161
+ ) -> Expression:
162
+ return Cast(expression, ColumnType(name="TEXT", parameters=[]))
163
+
164
+ @staticmethod
165
+ def __to_pure_func(op_expr: str, config: FrameToPureConfig) -> str:
166
+ return generate_pure_functional_call("toString", [op_expr])
167
+
168
+ def __init__(self, operand: PyLegendExpression) -> None:
169
+ PyLegendExpressionStringReturn.__init__(self)
170
+ PyLegendUnaryExpression.__init__(
171
+ self,
172
+ operand,
173
+ PyLegendPrimitiveToStringExpression.__to_sql_func,
174
+ PyLegendPrimitiveToStringExpression.__to_pure_func,
175
+ non_nullable=True,
176
+ operand_needs_to_be_non_nullable=True,
177
+ )