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

Function field

python/pyarrow/compute.py:690–736  ·  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

688
689
690def 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
739def 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