Split a table according to `split_expression` condition. Args: split_expression: `ColumnExpression` that specifies the split condition. Returns: positive_table, negative_table: tuple of tables, with the same schemas as `self` and with ids that are
(
self, split_expression: expr.ColumnExpression
)
| 536 | @desugar |
| 537 | @check_arg_types |
| 538 | def split( |
| 539 | self, split_expression: expr.ColumnExpression |
| 540 | ) -> tuple[Table[TSchema], Table[TSchema]]: |
| 541 | """Split a table according to `split_expression` condition. |
| 542 | |
| 543 | |
| 544 | Args: |
| 545 | split_expression: `ColumnExpression` that specifies the split condition. |
| 546 | |
| 547 | Returns: |
| 548 | positive_table, negative_table: tuple of tables, |
| 549 | with the same schemas as `self` and with ids that are subsets of `self.id`, |
| 550 | and provably disjoint. |
| 551 | |
| 552 | |
| 553 | Example: |
| 554 | |
| 555 | >>> import pathway as pw |
| 556 | >>> vertices = pw.debug.table_from_markdown(''' |
| 557 | ... label outdegree |
| 558 | ... 1 3 |
| 559 | ... 7 0 |
| 560 | ... ''') |
| 561 | >>> positive, negative = vertices.split(vertices.outdegree == 0) |
| 562 | >>> pw.debug.compute_and_print(positive, include_id=False) |
| 563 | label | outdegree |
| 564 | 7 | 0 |
| 565 | >>> pw.debug.compute_and_print(negative, include_id=False) |
| 566 | label | outdegree |
| 567 | 1 | 3 |
| 568 | """ |
| 569 | positive = self.filter(split_expression) |
| 570 | negative = self.filter(~split_expression) |
| 571 | universes.promise_are_pairwise_disjoint(positive, negative) |
| 572 | universes.promise_are_equal( |
| 573 | self, Table.concat(positive, negative) |
| 574 | ) # TODO: add API method for this |
| 575 | return positive, negative |
| 576 | |
| 577 | @contextualized_operator |
| 578 | def _filter(self, filter_expression: expr.ColumnExpression) -> Table[TSchema]: |