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

Function field

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

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

Callers 11

_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 10

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