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

Method reduce

python/pathway/internals/table.py:1276–1309  ·  view source on GitHub ↗

Reduce a table to a single row. Equivalent to `self.groupby().reduce(*args, **kwargs)`. Args: args: reducer to reduce the table with kwargs: reducer to reduce the table with. Its key is the new name of a column. Returns: Table: Reduced t

(
        self, *args: expr.ColumnReference, **kwargs: expr.ColumnExpression
    )

Source from the content-addressed store, hash-verified

1274 @desugar
1275 @arg_handler(handler=reduce_args_handler)
1276 def reduce(
1277 self, *args: expr.ColumnReference, **kwargs: expr.ColumnExpression
1278 ) -> Table:
1279 """Reduce a table to a single row.
1280
1281 Equivalent to `self.groupby().reduce(*args, **kwargs)`.
1282
1283 Args:
1284 args: reducer to reduce the table with
1285 kwargs: reducer to reduce the table with. Its key is the new name of a column.
1286
1287 Returns:
1288 Table: Reduced table.
1289
1290 Example:
1291
1292 >>> import pathway as pw
1293 >>> t1 = pw.debug.table_from_markdown('''
1294 ... age | owner | pet
1295 ... 10 | Alice | dog
1296 ... 9 | Bob | dog
1297 ... 8 | Alice | cat
1298 ... 7 | Bob | dog
1299 ... ''')
1300 >>> t2 = t1.reduce(ageagg=pw.reducers.argmin(t1.age))
1301 >>> pw.debug.compute_and_print(t2, include_id=False) # doctest: +ELLIPSIS
1302 ageagg
1303 ^...
1304 >>> t3 = t2.select(t1.ix(t2.ageagg).age, t1.ix(t2.ageagg).pet)
1305 >>> pw.debug.compute_and_print(t3, include_id=False)
1306 age | pet
1307 7 | dog
1308 """
1309 return self.groupby().reduce(*args, **kwargs)
1310
1311 @trace_user_frame
1312 @desugar

Callers 15

build_pipelineMethod · 0.45
inputs_queryMethod · 0.45
_apply_rerankingMethod · 0.45
inputs_queryMethod · 0.45
callbackMethod · 0.45
types_lca_manyFunction · 0.45
_unionFunction · 0.45
_intersectFunction · 0.45
_selectFunction · 0.45
_create_input_tableFunction · 0.45
multiapply_all_rowsFunction · 0.45

Calls 1

groupbyMethod · 0.95

Tested by 15

test_lshFunction · 0.36
test_lsh_bucketingFunction · 0.36
test_method_in_ixFunction · 0.36
test_method_in_groupbyFunction · 0.36
test_groupbyFunction · 0.36
test_custom_count_staticFunction · 0.36
test_custom_count_nullFunction · 0.36
test_custom_mean_stdevFunction · 0.36