o
    `۷i                     @  sh   d dl mZ d dlZd dlmZmZ d dlZd dlZ	d dl
mZ dddZ	dddd	dd
dddZdS )    )annotationsN)ListUnioncountspa.Arrayreturnc                 C  s&   t | }ttjdg|jd|gS )z:Convert per-row counts to list offsets via cumulative sum.r   type)pccumulative_sumpaconcat_arraysarrayr	   )r   cumsum r   T/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/data/_internal/arrow_utils.py_counts_to_offsets   s   
r   F)offsetsvaluesis_large	null_maskcolumn_values-List[Union[pa.Array, pa.ChunkedArray]] | Noner   pa.Array | Noner   r   boolr   c          	      C  s   | du r|du s|du rt dn.dd | D }|rt nt }tjtdgt|g|d}tt	j
dd | D  }|rEt nt }t||}|rTtjntj}|r_t|jnt|j}|j||||dS )	zBCombine list arrays or build a list array from offsets and values.NzAEither column_values or both offsets and values must be provided.c                 S  s   g | ]}t |qS r   )len.0vr   r   r   
<listcomp>    s    z*_combine_as_list_array.<locals>.<listcomp>r   r   c                 S  s$   g | ]}t |tjr|jn|gqS r   )
isinstancer   ChunkedArraychunksr   r   r   r   r   %   s    )mask)
ValueErrorr   int64int32r   npconcatenater   r   	itertoolschainr
   castLargeListArray	ListArray
large_listr	   list_from_arrays)	r   r   r   r   r   lensoffsets_type	array_cls	list_typer   r   r   _combine_as_list_array   s*   	 	r5   )r   r   r   r   )N)r   r   r   r   r   r   r   r   r   r   r   r   )
__future__r   r)   typingr   r   numpyr'   pyarrowr   pyarrow.computecomputer
   r   r5   r   r   r   r   <module>   s    
