o
    Zh                     @   s   d dl Z d dlZd dlZd dlmZ dd Zdd Z		dddZ	dd	d
Z
dd Zdd Zdd ZdddZdd ZdddZdS )    N)utilc                 K   sF   dd l m} ddlm} || rtj| } |j| |fi | | S )Nr   )_pandas_api)	pyarrow.parquetparquetZpyarrow.pandas_compatr   Zis_data_framepaTablefrom_pandasZwrite_table)tablepathkwargspqr    r   S/var/www/html/lang_env/lib/python3.10/site-packages/pyarrow/tests/parquet/common.py_write_table   s   
r   c                  O   s,   dd l m} |j| i |}|jdd |S )Nr   T)full)r   r   Z
read_tablevalidate)argsr   r   r	   r   r   r   _read_table&   s   r   c                 C   sH   |pi }|pi }t  }t| |fi | t | }t|fi |S )N)r   ZBufferOutputStreamr   ZBufferReadergetvaluer   )r	   read_table_kwargswrite_table_kwargswriterreaderr   r   r   _roundtrip_table.   s   r   c                 K   sP   |d u r| }|p	i }t | ||d}||sJ t |||d}||s&J d S )N)r   r   )r   equals)r	   expectedr   r   resultr   r   r   _check_roundtrip9   s   r   c                 C   s    t j| }t||d}| S )N)r   )r   r   r   r   Z	to_pandas)dfZwrite_kwargsr	   r   r   r   r   _roundtrip_pandas_dataframeI   s
   r   c                 C   s@   t d}t |}t jjt|j|jt|j|j| d|S )Nint_)size)npiinforandomrandintmaxminastype)r!   dtypeZplatform_int_infor#   r   r   r   _random_integersP   s   

r*   c                 C   s   t tj| |dS )Nr)   )r   arrayr"   arange)r!   r)   r   r   r   _range_integersY   s   r.   '  c                 C   s   dd l }tj| |t| tjt| tjt| tjt| tj	t| tj
t| tjt| tjt| tjtj| tjtj| tjdtj| dkdd t| D d g|  d g|  d}|S )Nr   r+   c                 S   s   g | ]}t d qS )
   )r   Zrands).0ir   r   r   
<listcomp>m   s    z#_test_dataframe.<locals>.<listcomp>)uint8uint16uint32uint64int8int16int32int64float32float64boolstringsZall_noneZall_none_category)pandasr"   r$   seed	DataFramer*   r4   r5   r6   r7   r8   r9   r:   r;   randnr(   r<   r-   r=   range)r!   rA   pdr   r   r   r   _test_dataframe]   s&   







rF   c                 C   sV   dd l m} t| tjr| }ntj| }t }t||ddd |	d |
|S )Nr   ZSNAPPYz2.6)compressionversion)r   r   
isinstancer   r   r   ioBytesIOr   seekZParquetFile)Ztable_or_dfr   Za_tablebufr   r   r   make_sample_filew   s   

rN   Fc                 C   s  dd l }tj| i dtj| tjddtj| tjddtj| tjddtj| tjddtj| tj	ddtj| tj	dd	tj| tj
dd
tj| tjddtj| tjddtj| tjddtj| dkdtjd| dddtjd| dddtjd| dddtjd| ddd|dd t| D ddg|  d gdd t| d D  d g d g|  d gd d d t| d D  d!}|r|d d"|d#< ||S )$Nr   r4   r+   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   Zdatetime_msz2016-01-01T00:00:00.001zdatetime64[ms]Zdatetime_usz2016-01-01T00:00:00.000001zdatetime64[us]Zdatetime_nsz2016-01-01T00:00:00.000000001zdatetime64[ns]	timedeltaztimedelta64[s]strc                 S      g | ]}t |qS r   rP   r1   xr   r   r   r3          z#alltypes_sample.<locals>.<listcomp>Z	empty_str c                 S   rQ   r   rR   rS   r   r   r   r3      rU      c                 S   s   g | ]	}d g|d  qS )N   r   rS   r   r   r   r3      s    )Zstr_with_nullsnullZ	null_listcategoryZstr_category)r@   r"   r$   rA   r-   r4   r5   r6   r7   r9   r:   r;   r<   r=   rC   ZSeriesrD   r(   rB   )r!   rA   ZcategoricalrE   Zarraysr   r   r   alltypes_sample   sd   	




 
r[   )NN)r/   r   )r/   r   F)rJ   numpyr"   Zpyarrowr   Zpyarrow.testsr   r   r   r   r   r   r*   r.   rF   rN   r[   r   r   r   r   <module>   s    

	
