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,
)
| 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: |
no test coverage detected