MCPcopy Create free account
hub / github.com/apache/arrow / field

Function field

python/pyarrow/compute.py:701–747  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 10

_dataset_to_declFunction · 0.90
test_declarationFunction · 0.90
test_filterFunction · 0.90
test_projectFunction · 0.90
test_aggregate_scalarFunction · 0.90
test_aggregate_hashFunction · 0.90
test_order_byFunction · 0.90
test_hash_joinFunction · 0.90
test_asof_joinFunction · 0.90
test_scanFunction · 0.90

Calls 3

lenFunction · 0.85
TypeErrorFunction · 0.50
typeEnum · 0.50

Tested by 9

test_declarationFunction · 0.72
test_filterFunction · 0.72
test_projectFunction · 0.72
test_aggregate_scalarFunction · 0.72
test_aggregate_hashFunction · 0.72
test_order_byFunction · 0.72
test_hash_joinFunction · 0.72
test_asof_joinFunction · 0.72
test_scanFunction · 0.72