MCPcopy
hub / github.com/pathwaycom/pathway / apply

Function apply

python/pathway/internals/common.py:96–129  ·  view source on GitHub ↗

Applies function to column expressions, column-wise. Output column type deduced from type-annotations of a function. Example: >>> import pathway as pw >>> def concat(left: str, right: str) -> str: ... return left+right >>> t1 = pw.debug.table_from_markdown(''' ... age

(
    fun: Callable,
    *args: expr.ColumnExpression | Value,
    **kwargs: expr.ColumnExpression | Value,
)

Source from the content-addressed store, hash-verified

94@check_arg_types
95@trace_user_frame
96def apply(
97 fun: Callable,
98 *args: expr.ColumnExpression | Value,
99 **kwargs: expr.ColumnExpression | Value,
100) -> expr.ColumnExpression:
101 """Applies function to column expressions, column-wise.
102 Output column type deduced from type-annotations of a function.
103
104 Example:
105
106 >>> import pathway as pw
107 >>> def concat(left: str, right: str) -> str:
108 ... return left+right
109 >>> t1 = pw.debug.table_from_markdown('''
110 ... age owner pet
111 ... 10 Alice dog
112 ... 9 Bob dog
113 ... 8 Alice cat
114 ... 7 Bob dog''')
115 >>> t2 = t1.select(col = pw.apply(concat, t1.owner, t1.pet))
116 >>> pw.debug.compute_and_print(t2, include_id=False)
117 col
118 Alicecat
119 Alicedog
120 Bobdog
121 Bobdog
122 """
123 if kwargs:
124 warn(
125 "Passing keyword arguments to the function in pw.apply is deprecated. Use positional arguments instead.",
126 DeprecationWarning,
127 stacklevel=5,
128 )
129 return udf(fun)(*args, **kwargs)
130
131
132def apply_with_type(

Callers 3

test_bucketer_euclideanFunction · 0.90
test_bucketer_cosineFunction · 0.90
test_lshFunction · 0.90

Calls 1

udfFunction · 0.90

Tested by 3

test_bucketer_euclideanFunction · 0.72
test_bucketer_cosineFunction · 0.72
test_lshFunction · 0.72