gigl.src.data_preprocessor.lib.transform.arrow_utils#
Helpers for turning Arrow columns into numpy arrays without copying.
Functions#
|
Returns a column holding one list per row as a |
Module Contents#
- gigl.src.data_preprocessor.lib.transform.arrow_utils.list_column_to_numpy(column, num_rows)[source]#
Returns a column holding one list per row as a
[num_rows, width]numpy array.TFT emits every output as a list column with one fixed-length list per row. The values are returned as a view of the Arrow buffers whenever the value type allows it. A plain primitive column is returned as a width-1 matrix.
The values are checked in total only: the number of values must divide evenly by
num_rows, but each row’s length is not checked. This is enough for TFT dense outputs, whose shapes are fixed. Checking every row costs about as much as the conversion itself for batches with hundreds of scalar columns.Example
>>> column = pa.array([[1, 2], [3, 4], [5, 6]]) >>> list_column_to_numpy(column.slice(1, 2), num_rows=2) array([[3, 4], [5, 6]])
- Parameters:
column (pyarrow.Array) – A
list,large_list,fixed_size_listor primitive array. May be a slice of a larger array.num_rows (int) – Number of rows in the column.
- Returns:
A
[num_rows, width]array in the column’s value type.- Raises:
ValueError – If the column length differs from
num_rows, the column or its values contain nulls, or the number of values is not a multiple ofnum_rows.- Return type:
numpy.ndarray