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

Method ix

python/pathway/internals/table.py:1416–1525  ·  view source on GitHub ↗

Reindexes the table using expression values as 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 RuntimeEr

(
        self,
        expression: expr.ColumnExpression,
        *,
        optional: bool = False,
        context=None,
        allow_misses: bool = False,
    )

Source from the content-addressed store, hash-verified

1414
1415 @trace_user_frame
1416 def ix(
1417 self,
1418 expression: expr.ColumnExpression,
1419 *,
1420 optional: bool = False,
1421 context=None,
1422 allow_misses: bool = False,
1423 ) -> Table:
1424 """Reindexes the table using expression values as keys. Uses keys from context, or tries to infer
1425 proper context from the expression.
1426 If optional is True, then None in expression values result in None values in the result columns.
1427 Missing values in table keys result in RuntimeError.
1428 If ``allow_misses`` is set to True, they result in None value on the output.
1429
1430 Context can be anything that allows for `select` or `reduce`, or `pathway.this` construct
1431 (latter results in returning a delayed operation, and should be only used when using `ix` inside
1432 join().select() or groupby().reduce() sequence).
1433
1434 Returns:
1435 Reindexed table with the same set of columns.
1436
1437 Example:
1438
1439 >>> import pathway as pw
1440 >>> t_animals = pw.debug.table_from_markdown('''
1441 ... | epithet | genus
1442 ... 1 | upupa | epops
1443 ... 2 | acherontia | atropos
1444 ... 3 | bubo | scandiacus
1445 ... 4 | dynastes | hercules
1446 ... ''')
1447 >>> t_birds = pw.debug.table_from_markdown('''
1448 ... | desc
1449 ... 2 | hoopoe
1450 ... 4 | owl
1451 ... ''')
1452 >>> ret = t_birds.select(t_birds.desc, latin=t_animals.ix(t_birds.id).genus)
1453 >>> pw.debug.compute_and_print(ret, include_id=False)
1454 desc | latin
1455 hoopoe | atropos
1456 owl | hercules
1457 """
1458
1459 if context is None:
1460 all_tables = collect_tables(expression)
1461 if len(all_tables) == 0:
1462 context = thisclass.this
1463 elif all(tab == all_tables[0] for tab in all_tables):
1464 context = all_tables[0]
1465 if context is None:
1466 for tab in all_tables:
1467 if not isinstance(tab, Table):
1468 raise ValueError("Table expected here.")
1469 if len(all_tables) == 0:
1470 raise ValueError("Const value provided.")
1471 context = all_tables[0]
1472 for tab in all_tables:
1473 assert context._universe.is_equal_to(tab._universe)

Callers 15

ix_refMethod · 0.95
groupby_reduce_majorityFunction · 0.45
_compute_group_reprMethod · 0.45
merge_ccsMethod · 0.45
_build_groupsFunction · 0.45
merge_ccsFunction · 0.45
_mergeMethod · 0.45
fill_peerMethod · 0.45
_contractFunction · 0.45
_contract_weightedFunction · 0.45
_bellman_ford_stepFunction · 0.45
pagerankFunction · 0.45

Calls 15

update_typesMethod · 0.95
typehintsMethod · 0.95
keysMethod · 0.95
column_namesMethod · 0.95
collect_tablesFunction · 0.90
is_equal_toMethod · 0.80
eval_typeMethod · 0.80
_havingMethod · 0.80
restrictMethod · 0.80
differenceMethod · 0.80
with_universe_ofMethod · 0.80

Tested by 15

get_differencesFunction · 0.36
test_linked_list_forwardFunction · 0.36
min_id_removeFunction · 0.36
test_ixFunction · 0.36
test_ix_noneFunction · 0.36
test_ix_this_getitemFunction · 0.36
test_ix_missing_keyFunction · 0.36
test_ix_none_in_sourceFunction · 0.36