udf_model

compiler

class BinOp(val: 'str', left: 't.Optional[Node]' = None, right: 't.Optional[Node]' = None)

Bases: Node

accept_children(visitor)
left: Node | None = None
right: Node | None = None
class Func(val: 'str', args: 't.Tuple[Node, ...]' = ())

Bases: Node

accept_children(visitor)
args: Tuple[Node, ...] = ()
class Node(val: 'str')

Bases: object

accept(visitor, top_down=False)

Accept a visitor and traverse the tree. Branch nodes must override Node.accept_children

Parameters:
  • visitor – the Visitor

  • top_down – whether to first the branch nodes and then the children (top_down=True) or first the children and then the branch nodes (top_down=False)

accept_children(visitor)

Branch nodes should override this to let the visitor visit the node’s children

accept_node(visitor)

Accept a visitor but do not traverse any children. The visitor is responsible for traversing the tree.

val: str
class NodeVisitor

Bases: object

visit(node: Node)
class Num(val: 'str')

Bases: Node

class Parser(tokenizer: Iterable)

Bases: object

A simple recursive descent parser

add_expr()

add_expr : [“+”|”-”] mul_expr ((“+” | “-”) mul_expr)*

atom()

factor : num | function_or_name | “(” expr “)”

comp_expr()

comp_expr: add_expr ((“==” | “!=”) add_expr)*

current_token: Token
error()
expect(*token_type: str)
expr()
function_or_name()

function_or_name : name “(” expr? (“,” expr)* “)” | name

ignore = ('ws',)
mul_expr()

mul_expr : atom ((MUL | DIV) atom)*

next_valid_token()
parse()
peek(*token_type)
class Token(type, text)

Bases: NamedTuple

text: str

Alias for field number 1

type: str

Alias for field number 0

class UDFCompiler

Bases: NodeVisitor

visit(node: Node)
visit(node: Var)
visit(node: Num)
visit(node: BinOp)
visit(node: Func)
class Var(val: 'str')

Bases: Node

class VariableNameCollector

Bases: NodeVisitor

visit(node: Node)
visit(node: Var)
compile(string)
compile_func(node: Node)
get_vars(node: Node)
parse(tokens: Iterable[Token])
tokenize(string: str, patterns: dict | None = None) Iterator[Token]

functions

default_func(arr: TrackedCSRArray | ndarray, default_val: float | TrackedCSRArray | ndarray)
func(name: str)
if_func(*arrays_or_values)
max_func(*arrays_or_values)

calculate row-wise maximum value of n arrays or values. Every array must have the same length in the first dimension. Values are broadcasted along the first axis

min_func(*arrays_or_values)

calculate row-wise minimum value of n arrays or values. Every array must have the same length in the first dimension. Values are broadcasted along the first axis

sum_func(arr)

udf_model

class UDF(func, output_attr)

Bases: object

run(inputs: Dict[str, UniformAttribute | CSRAttribute])
class UDFInfo(dataset: 'str', entity_group: 'str', expression: 'str', output_attribute: 'str')

Bases: object

dataset: str
entity_group: str
expression: str
get_output_attribute(state: TrackedState, schema: AttributeSchema, replace_sub=True)
make_udf(state: TrackedState, schema: AttributeSchema, replace_sub=True)
output_attribute: str
class UDFModel(model_config: dict)

Bases: TrackedModel

inputs: t.Dict[str, AttributeObject]
run_udfs()
setup(state: TrackedState, schema: AttributeSchema, **_)
udfs: t.List[UDF]
update(**_)
convert_v1_v2(config)
get_input_attributes(config: dict, schema: AttributeSchema, state: TrackedState)
get_udf_infos(config)
prepare_optional_attributes(config, inputs: Dict[str, UniformAttribute | CSRAttribute])