MCPcopy
hub / github.com/pathwaycom/pathway / get

Method get

python/pathway/internals/expression.py:360–399  ·  view source on GitHub ↗

Extracts element at `index` from an object. The object has to be a Tuple or Json. If no element is present at `index`, it returns value specified by a `default` parameter. Index can be effectively `int` for Tuple and `int` or `str` for Json. For Tuples, using negative index

(
        self,
        index: ColumnExpression | int | str,
        default: ColumnExpression | Value = None,
    )

Source from the content-addressed store, hash-verified

358 return GetExpression(self, index, check_if_exists=False)
359
360 def get(
361 self,
362 index: ColumnExpression | int | str,
363 default: ColumnExpression | Value = None,
364 ) -> ColumnExpression:
365 """Extracts element at `index` from an object. The object has to be a Tuple or Json.
366 If no element is present at `index`, it returns value specified by a `default` parameter.
367
368 Index can be effectively `int` for Tuple and `int` or `str` for Json.
369 For Tuples, using negative index can be used to access elements at the end, moving backwards.
370
371 Args:
372 index: Position to extract element at.
373 default: Value returned when no element is at position `index`. Defaults to None.
374
375 Example:
376
377 >>> import pathway as pw
378 >>> t1 = pw.debug.table_from_markdown(
379 ... '''
380 ... | a | b | c
381 ... 1 | 3 | 2 | 2
382 ... 2 | 4 | 1 | 0
383 ... 3 | 7 | 3 | 1
384 ... '''
385 ... )
386 >>> t2 = t1.with_columns(tup=pw.make_tuple(pw.this.a, pw.this.b))
387 >>> t3 = t2.select(
388 ... x=pw.this.tup.get(1),
389 ... y=pw.this.tup.get(3),
390 ... z=pw.this.tup.get(pw.this.c),
391 ... t=pw.this.tup.get(pw.this.c, default=100),
392 ... )
393 >>> pw.debug.compute_and_print(t3, include_id=False)
394 x | y | z | t
395 1 | | 4 | 4
396 2 | | | 100
397 3 | | 3 | 3
398 """
399 return GetExpression(self, index, default, check_if_exists=True)
400
401 @property
402 def dt(self) -> DateTimeNamespace:

Callers 15

factoryFunction · 0.45
_snapshot_accessFunction · 0.45
_persistence_modeFunction · 0.45
get_pathway_configFunction · 0.45
create_column_definitionFunction · 0.45
get_operators_tableMethod · 0.45
eval_column_valMethod · 0.45
eval_column_valMethod · 0.45
desugarFunction · 0.45
__init__Method · 0.45
output_nameMethod · 0.45
_resolve_variableMethod · 0.45

Calls 1

GetExpressionClass · 0.85

Tested by

no test coverage detected