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

Function create_sample_expressions

python/pyarrow/tests/test_compute.py:4092–4164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4090
4091
4092def create_sample_expressions():
4093 # We need a schema for substrait conversion
4094 schema = pa.schema([pa.field("i64", pa.int64()), pa.field(
4095 "foo", pa.struct([pa.field("bar", pa.string())]))])
4096
4097 # Creates a bunch of sample expressions for testing
4098 # serialization and deserialization. The expressions are categorized
4099 # to reflect certain nuances in Substrait conversion.
4100 a = pc.scalar(1)
4101 b = pc.scalar(1.1)
4102 c = pc.scalar(True)
4103 d = pc.scalar("string")
4104 e = pc.scalar(None)
4105 f = pc.scalar({'a': 1})
4106 g = pc.scalar(pa.scalar(1))
4107 h = pc.scalar(np.int64(2))
4108 j = pc.scalar(False)
4109 k = pc.scalar(0)
4110
4111 # These expression consist entirely of literals
4112 literal_exprs = [a, b, c, d, e, g, h, j, k]
4113
4114 # These expressions include at least one function call
4115 exprs_with_call = [a == b, a != b, a > b, c & j, c | j, ~c, d.is_valid(),
4116 a + b, a - b, a * b, a / b, pc.negate(a),
4117 pc.add(a, b), pc.subtract(a, b), pc.divide(a, b),
4118 pc.multiply(a, b), pc.power(a, a), pc.sqrt(a),
4119 pc.exp(b), pc.cos(b), pc.sin(b), pc.tan(b),
4120 pc.acos(b), pc.atan(b), pc.asin(b), pc.atan2(b, b),
4121 pc.sinh(a), pc.cosh(a), pc.tanh(a),
4122 pc.asinh(a), pc.acosh(b), pc.atanh(k),
4123 pc.abs(b), pc.sign(a), pc.bit_wise_not(a),
4124 pc.bit_wise_and(a, a), pc.bit_wise_or(a, a),
4125 pc.bit_wise_xor(a, a), pc.is_nan(b), pc.is_finite(b),
4126 pc.coalesce(a, b),
4127 a.cast(pa.int32(), safe=False)]
4128
4129 # These expressions test out various reference styles and may include function
4130 # calls. Named references are used here.
4131 exprs_with_ref = [pc.field('i64') > 5, pc.field('i64') == 5,
4132 pc.field('i64') == 7,
4133 pc.field(('foo', 'bar')) == 'value',
4134 pc.field('foo', 'bar') == 'value']
4135
4136 # Similar to above but these use numeric references instead of string refs
4137 exprs_with_numeric_refs = [pc.field(0) > 5, pc.field(0) == 5,
4138 pc.field(0) == 7,
4139 pc.field((1, 0)) == 'value',
4140 pc.field(1, 0) == 'value']
4141
4142 # Expressions that behave uniquely when converting to/from substrait
4143 special_cases = [
4144 f, # Struct literals lose their field names
4145 a.isin([1, 2, 3]), # isin converts to an or list
4146 pc.field('i64').is_null() # pyarrow always specifies a FunctionOptions
4147 # for is_null which, being the default, is
4148 # dropped on serialization
4149 ]

Calls 11

signMethod · 0.80
is_nullMethod · 0.80
copyMethod · 0.80
schemaMethod · 0.45
fieldMethod · 0.45
stringMethod · 0.45
scalarMethod · 0.45
is_validMethod · 0.45
negateMethod · 0.45
absMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected