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

Method ix_ref

python/pathway/internals/table.py:2662–2749  ·  view source on GitHub ↗

Reindexes the table using expressions as primary keys. Uses keys from context, or tries to infer proper context from the expression. If ``optional`` is True, then None in expression values result in None values in the result columns. Missing values in table keys result in Run

(
        self,
        *args: expr.ColumnExpression | Value,
        optional: bool = False,
        context=None,
        instance: expr.ColumnReference | None = None,
        allow_misses: bool = False,
    )

Source from the content-addressed store, hash-verified

2660
2661 @trace_user_frame
2662 def ix_ref(
2663 self,
2664 *args: expr.ColumnExpression | Value,
2665 optional: bool = False,
2666 context=None,
2667 instance: expr.ColumnReference | None = None,
2668 allow_misses: bool = False,
2669 ):
2670 """Reindexes the table using expressions as primary keys.
2671 Uses keys from context, or tries to infer proper context from the expression.
2672 If ``optional`` is True, then None in expression values result in None values in the result columns.
2673 Missing values in table keys result in RuntimeError.
2674 If ``allow_misses`` is set to True, they result in None value on the output.
2675
2676 Context can be anything that allows for `select` or `reduce`, or `pathway.this` construct
2677 (latter results in returning a delayed operation, and should be only used when using `ix` inside
2678 join().select() or groupby().reduce() sequence).
2679
2680
2681 Args:
2682 args: Column references.
2683
2684 Returns:
2685 Row: indexed row.
2686
2687 Example:
2688
2689 >>> import pathway as pw
2690 >>> t1 = pw.debug.table_from_markdown('''
2691 ... name | pet
2692 ... Alice | dog
2693 ... Bob | cat
2694 ... Carole | cat
2695 ... David | dog
2696 ... ''')
2697 >>> t2 = t1.with_id_from(pw.this.name)
2698 >>> t2 = t2.select(*pw.this, new_value=pw.this.ix_ref("Alice").pet)
2699 >>> pw.debug.compute_and_print(t2, include_id=False)
2700 name | pet | new_value
2701 Alice | dog | dog
2702 Bob | cat | dog
2703 Carole | cat | dog
2704 David | dog | dog
2705
2706 Tables obtained by a groupby/reduce scheme always have primary keys:
2707
2708 >>> import pathway as pw
2709 >>> t1 = pw.debug.table_from_markdown('''
2710 ... name | pet
2711 ... Alice | dog
2712 ... Bob | cat
2713 ... Carole | cat
2714 ... David | cat
2715 ... ''')
2716 >>> t2 = t1.groupby(pw.this.pet).reduce(pw.this.pet, count=pw.reducers.count())
2717 >>> t3 = t1.select(*pw.this, new_value=t2.ix_ref(t1.pet).count)
2718 >>> pw.debug.compute_and_print(t3, include_id=False)
2719 name | pet | new_value

Calls 2

ixMethod · 0.95
pointer_fromMethod · 0.95