MCPcopy Index your code
hub / github.com/pathwaycom/pathway / filter

Method filter

python/pathway/internals/table.py:497–533  ·  view source on GitHub ↗

Filter a table according to `filter_expression` condition. Args: filter_expression: `ColumnExpression` that specifies the filtering condition. Returns: Table: Result has the same schema as `self` and its ids are subset of `self.id`. Example:

(self, filter_expression: expr.ColumnExpression)

Source from the content-addressed store, hash-verified

495 @desugar
496 @check_arg_types
497 def filter(self, filter_expression: expr.ColumnExpression) -> Table[TSchema]:
498 """Filter a table according to `filter_expression` condition.
499
500
501 Args:
502 filter_expression: `ColumnExpression` that specifies the filtering condition.
503
504 Returns:
505 Table: Result has the same schema as `self` and its ids are subset of `self.id`.
506
507
508 Example:
509
510 >>> import pathway as pw
511 >>> vertices = pw.debug.table_from_markdown('''
512 ... label outdegree
513 ... 1 3
514 ... 7 0
515 ... ''')
516 >>> filtered = vertices.filter(vertices.outdegree == 0)
517 >>> pw.debug.compute_and_print(filtered, include_id=False)
518 label | outdegree
519 7 | 0
520 """
521 filter_type = self.eval_type(filter_expression)
522 if filter_type != dt.BOOL:
523 raise TypeError(
524 f"Filter argument of Table.filter() has to be bool, found {filter_type}."
525 )
526 ret = self._filter(filter_expression)
527 if (
528 filter_col := expr.get_column_filtered_by_is_none(filter_expression)
529 ) is not None and filter_col.table == self:
530 name = filter_col.name
531 dtype = self._columns[name].dtype
532 ret = ret.update_types(**{name: dt.unoptionalize(dtype)})
533 return ret
534
535 @trace_user_frame
536 @desugar

Callers 15

splitMethod · 0.95
_wrapFunction · 0.45
_selectFunction · 0.45
successfulMethod · 0.45
failedMethod · 0.45
inactivity_detectionFunction · 0.45
_interval_joinMethod · 0.45
_joinMethod · 0.45
_assign_sliding_windowsFunction · 0.45
_build_groupsFunction · 0.45
fill_peerMethod · 0.45

Calls 3

eval_typeMethod · 0.95
_filterMethod · 0.95
update_typesMethod · 0.80

Tested by 15

get_differencesFunction · 0.36
test_py_objectFunction · 0.36
test_filterFunction · 0.36
test_filter_no_columnsFunction · 0.36
min_id_removeFunction · 0.36
test_join_ixFunction · 0.36
test_multiple_ixFunction · 0.36
test_join_filter_1Function · 0.36
test_join_filter_2Function · 0.36