Skip to content

Commit 310a93a

Browse files
committed
checkpoint: refactor arg rendering
1 parent 8019f08 commit 310a93a

3 files changed

Lines changed: 27 additions & 40 deletions

File tree

packages/bigframes/scripts/generate_bigframes_bigquery/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def main():
3333

3434
for yaml_file in sorted(constants.DATA_DIR.glob("**/*.yaml")):
3535
modules.append(yaml_parser.parse_yaml(yaml_file))
36-
break
3736

3837
file_generator.generate(modules)
3938

packages/bigframes/scripts/generate_bigframes_bigquery/data_models.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ class BQFuncArg:
2727
optional: bool
2828
keyword_only: bool
2929

30-
31-
@dataclasses.dataclass
32-
class BigFramesFuncArg:
33-
name: str
34-
types: set[str]
35-
optional: bool
36-
keyword_only: bool
37-
38-
3930
@dataclasses.dataclass
4031
class BQFuncImpl:
4132
args: list[BQFuncArg]
@@ -89,10 +80,34 @@ class BigFramesOp:
8980
signature_definition: str | None
9081

9182

83+
@dataclasses.dataclass
84+
class BigFramesFuncArg:
85+
name: str
86+
types: set[str]
87+
optional: bool
88+
keyword_only: bool
89+
90+
@property
91+
def type_hint(self) -> str:
92+
types = [constants.PY_TYPE_MAP.get(t, "Any") for t in sorted(self.types)] + [
93+
"Literal[sentinels.Sentinel.ARGUMENT_DEFAULT]"
94+
]
95+
96+
if len(types) > 1:
97+
return "Union[" + ", ".join(sorted(set(types))) + "]"
98+
99+
return types[0]
100+
101+
@property
102+
def default(self) -> str | None:
103+
if self.optional:
104+
return "sentinels.Sentinel.ARGUMENT_DEFAULT"
105+
return None
106+
107+
92108
@dataclasses.dataclass
93109
class BigFramesFunc:
94110
name: str
95111
op_name: str
96112
description: str
97-
args: list[str]
98-
series_accessor_arg: list[str]
113+
args: list[BigFramesFuncArg]

packages/bigframes/scripts/generate_bigframes_bigquery/template_renderer.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,32 +171,6 @@ def _to_bigframes_op(bq_func: data_models.BQFunc) -> data_models.BigFramesOp:
171171

172172

173173
def _to_bigframes_func(bq_func: data_models.BQFunc) -> data_models.BigFramesFunc:
174-
func_args = []
175-
for arg in _get_bigframes_func_args(bq_func):
176-
types = [constants.PY_TYPE_MAP.get(t, "Any") for t in sorted(arg.types)] + [
177-
"Literal[sentinels.Sentinel.ARGUMENT_DEFAULT]"
178-
]
179-
type_hint = (
180-
"Union[" + ", ".join(sorted(set(types))) + "]"
181-
if len(types) > 1
182-
else types[0]
183-
)
184-
func_args.append(
185-
{
186-
"name": arg.name,
187-
"type_hint": type_hint,
188-
"default": (
189-
"sentinels.Sentinel.ARGUMENT_DEFAULT" if arg.optional else ""
190-
),
191-
}
192-
)
193-
194-
# Clean up default values for mandatory args
195-
# In Python, mandatory args come first.
196-
for arg in func_args:
197-
if not arg.get("default"):
198-
arg.pop("default", None)
199-
200174
python_name = bq_func.op_base_name
201175
if python_name in constants.PYTHON_BUILTINS:
202176
python_name = python_name + "_"
@@ -205,8 +179,7 @@ def _to_bigframes_func(bq_func: data_models.BQFunc) -> data_models.BigFramesFunc
205179
name=python_name,
206180
op_name=f"_{bq_func.op_base_name.upper()}_OP",
207181
description=bq_func.description,
208-
args=func_args,
209-
series_accessor_arg=[],
182+
args=_get_bigframes_func_args(bq_func),
210183
)
211184

212185

0 commit comments

Comments
 (0)