(func_fixture,
inputs, *,
run_in_dataset=True,
batch_length=None)
| 366 | |
| 367 | |
| 368 | def check_scalar_function(func_fixture, |
| 369 | inputs, *, |
| 370 | run_in_dataset=True, |
| 371 | batch_length=None): |
| 372 | function, name = func_fixture |
| 373 | if batch_length is None: |
| 374 | all_scalar = True |
| 375 | for arg in inputs: |
| 376 | if isinstance(arg, pa.Array): |
| 377 | all_scalar = False |
| 378 | batch_length = len(arg) |
| 379 | if all_scalar: |
| 380 | batch_length = 1 |
| 381 | |
| 382 | func = pc.get_function(name) |
| 383 | assert func.name == name |
| 384 | |
| 385 | result = pc.call_function(name, inputs, length=batch_length) |
| 386 | expected_output = function(mock_udf_context(batch_length), *inputs) |
| 387 | assert result == expected_output |
| 388 | # At the moment there is an issue when handling nullary functions. |
| 389 | # See: ARROW-15286 and ARROW-16290. |
| 390 | if run_in_dataset: |
| 391 | field_names = [f'field{index}' for index, in_arr in inputs] |
| 392 | table = pa.Table.from_arrays(inputs, field_names) |
| 393 | dataset = ds.dataset(table) |
| 394 | func_args = [ds.field(field_name) for field_name in field_names] |
| 395 | result_table = dataset.to_table( |
| 396 | columns={'result': ds.field('')._call(name, func_args)}) |
| 397 | assert result_table.column(0).chunks[0] == expected_output |
| 398 | |
| 399 | |
| 400 | def test_udf_array_unary(unary_func_fixture): |
no test coverage detected