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

Function struct_vector_func_fixture

python/pyarrow/tests/test_udf.py:348–365  ·  view source on GitHub ↗

Register a vector function that returns a struct array

()

Source from the content-addressed store, hash-verified

346
347@pytest.fixture(scope="session")
348def struct_vector_func_fixture():
349 """
350 Register a vector function that returns a struct array
351 """
352 def pivot(ctx, k, v, c):
353 df = pa.RecordBatch.from_arrays([k, v, c], names=['k', 'v', 'c']).to_pandas()
354 df_pivot = df.pivot(columns='c', values='v', index='k').reset_index()
355 return pa.RecordBatch.from_pandas(df_pivot).to_struct_array()
356
357 func_name = "y=pivot(x)"
358 doc = empty_udf_doc
359 pc.register_vector_function(
360 pivot, func_name, doc,
361 {'k': pa.int64(), 'v': pa.float64(), 'c': pa.utf8()},
362 pa.struct([('k', pa.int64()), ('v1', pa.float64()), ('v2', pa.float64())])
363 )
364
365 return pivot, func_name
366
367
368def check_scalar_function(func_fixture,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected