pathway.stdlib.indexing package
class pathway.stdlib.indexing.SortedIndex()
clear()
copy()
fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
items()
keys()
pop(k, )
If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
update(**F)
If E is present and has a .keys() method, then does: for k in E: Dk = Ek If E is present and lacks a .keys() method, then does: for k, v in E: Dk = v In either case, this is followed by: for k in F: Dk = Fk
values()
pathway.stdlib.indexing.retrieve_prev_next_values(ordered_table, value=None)
Retrieve, for each row, a pointer to the first row in the ordered_table that contains a non-“None” value, based on the orders defined by the prev and next columns.
- Parameters
- ordered_table (pw.Table) – Table with three columns: value, prev, next. The prev and next columns contain pointers to other rows.
- value (Optional*pw.ColumnReference*) – Column reference pointing to the column containing values. If not provided, assumes the column name is “value”.
- Returns
Table with two columns: prev_value and next_value.The prev_value column contains the values of the first row, according to the order defined by the column next, with a value different from None. The next_value column contains the values of the first row, according to the order defined by the column prev, with a value different from None. - Return type
pw.Table
pathway.stdlib.indexing.sort(table, key=None, instance=None)
Sorts a table by the specified keys.
- Parameters
- table (
Table
) – pw.Table The table to be sorted. - key (
Optional
[ColumnReference
]) – ColumnReference or None The name of the primary key to sort by. If None, the table is sorted based on the key column as primary key. - instance (
Optional
[ColumnReference
]) – ColumnReference or None The name of the secondary key to sort by. If None, the field “instance” is chosen if it exists, otherwise only the primary key is used.
- table (
- Returns
The sorted table. Contains two columns:prev
andnext
, containing the pointers to the previous and next rows. - Return type
pw.Table
Example:
import pathway as pw table = pw.debug.table_from_markdown(''' name | age | score Alice | 25 | 80 Bob | 20 | 90 Charlie | 30 | 80 ''') table = table.with_id_from(pw.this.name) table += sort(table, key=pw.this.age) pw.debug.compute_and_print(table)
| name | age | score | next | prev^GBSDEEW... | Alice | 25 | 80 | ^DS9AT95... | ^EDPSSB1...^EDPSSB1... | Bob | 20 | 90 | ^GBSDEEW... |^DS9AT95... | Charlie | 30 | 80 | | ^GBSDEEW...
Submodules
pathway.stdlib.indexing.sorting module
class pathway.stdlib.indexing.sorting.Aggregate()
class pathway.stdlib.indexing.sorting.BinsearchOracle()
class pathway.stdlib.indexing.sorting.Candidate()
class pathway.stdlib.indexing.sorting.ComparisonRet()
class pathway.stdlib.indexing.sorting.Hash()
class pathway.stdlib.indexing.sorting.Instance()
class pathway.stdlib.indexing.sorting.Key()
class pathway.stdlib.indexing.sorting.LeftRight()
class pathway.stdlib.indexing.sorting.Node()
class pathway.stdlib.indexing.sorting.Parent()
class pathway.stdlib.indexing.sorting.PrefixSumOracle()
class pathway.stdlib.indexing.sorting.PrevNext()
class pathway.stdlib.indexing.sorting.SortedIndex()
clear()
copy()
fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
items()
keys()
pop(k, )
If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
update(**F)
If E is present and has a .keys() method, then does: for k in E: Dk = Ek If E is present and lacks a .keys() method, then does: for k, v in E: Dk = v In either case, this is followed by: for k in F: Dk = Fk
values()
class pathway.stdlib.indexing.sorting.Value()
pathway.stdlib.indexing.sorting.retrieve_prev_next_values(ordered_table, value=None)
Retrieve, for each row, a pointer to the first row in the ordered_table that contains a non-“None” value, based on the orders defined by the prev and next columns.
- Parameters
- ordered_table (pw.Table) – Table with three columns: value, prev, next. The prev and next columns contain pointers to other rows.
- value (Optional*pw.ColumnReference*) – Column reference pointing to the column containing values. If not provided, assumes the column name is “value”.
- Returns
Table with two columns: prev_value and next_value.The prev_value column contains the values of the first row, according to the order defined by the column next, with a value different from None. The next_value column contains the values of the first row, according to the order defined by the column prev, with a value different from None. - Return type
pw.Table
pathway.stdlib.indexing.sorting.sort(table, key=None, instance=None)
Sorts a table by the specified keys.
- Parameters
- table (
Table
) – pw.Table The table to be sorted. - key (
Optional
[ColumnReference
]) – ColumnReference or None The name of the primary key to sort by. If None, the table is sorted based on the key column as primary key. - instance (
Optional
[ColumnReference
]) – ColumnReference or None The name of the secondary key to sort by. If None, the field “instance” is chosen if it exists, otherwise only the primary key is used.
- table (
- Returns
The sorted table. Contains two columns:prev
andnext
, containing the pointers to the previous and next rows. - Return type
pw.Table
Example:
import pathway as pw table = pw.debug.table_from_markdown(''' name | age | score Alice | 25 | 80 Bob | 20 | 90 Charlie | 30 | 80 ''') table = table.with_id_from(pw.this.name) table += sort(table, key=pw.this.age) pw.debug.compute_and_print(table)
| name | age | score | next | prev^GBSDEEW... | Alice | 25 | 80 | ^DS9AT95... | ^EDPSSB1...^EDPSSB1... | Bob | 20 | 90 | ^GBSDEEW... |^DS9AT95... | Charlie | 30 | 80 | | ^GBSDEEW...