Reference a column of the dataset. Stores only the field's name. Type and other information is known only when the expression is bound to a dataset having an explicit scheme. Nested references are allowed by passing multiple names or a tuple of names. For example ``('foo', 'bar')``
(*name_or_index)
| 688 | |
| 689 | |
| 690 | def field(*name_or_index): |
| 691 | """Reference a column of the dataset. |
| 692 | |
| 693 | Stores only the field's name. Type and other information is known only when |
| 694 | the expression is bound to a dataset having an explicit scheme. |
| 695 | |
| 696 | Nested references are allowed by passing multiple names or a tuple of |
| 697 | names. For example ``('foo', 'bar')`` references the field named "bar" |
| 698 | inside the field named "foo". |
| 699 | |
| 700 | Parameters |
| 701 | ---------- |
| 702 | *name_or_index : string, multiple strings, tuple or int |
| 703 | The name or index of the (possibly nested) field the expression |
| 704 | references to. |
| 705 | |
| 706 | Returns |
| 707 | ------- |
| 708 | field_expr : Expression |
| 709 | Reference to the given field |
| 710 | |
| 711 | Examples |
| 712 | -------- |
| 713 | >>> import pyarrow.compute as pc |
| 714 | >>> pc.field("a") |
| 715 | <pyarrow.compute.Expression a> |
| 716 | >>> pc.field(1) |
| 717 | <pyarrow.compute.Expression FieldPath(1)> |
| 718 | >>> pc.field(("a", "b")) |
| 719 | <pyarrow.compute.Expression FieldRef.Nested(FieldRef.Name(a) ... |
| 720 | >>> pc.field("a", "b") |
| 721 | <pyarrow.compute.Expression FieldRef.Nested(FieldRef.Name(a) ... |
| 722 | """ |
| 723 | n = len(name_or_index) |
| 724 | if n == 1: |
| 725 | if isinstance(name_or_index[0], (str, int)): |
| 726 | return Expression._field(name_or_index[0]) |
| 727 | elif isinstance(name_or_index[0], tuple): |
| 728 | return Expression._nested_field(name_or_index[0]) |
| 729 | else: |
| 730 | raise TypeError( |
| 731 | "field reference should be str, multiple str, tuple or " |
| 732 | f"integer, got {type(name_or_index[0])}" |
| 733 | ) |
| 734 | # In case of multiple strings not supplied in a tuple |
| 735 | else: |
| 736 | return Expression._nested_field(name_or_index) |
| 737 | |
| 738 | |
| 739 | def scalar(value): |