o
    Gh^                     @   s   d dl Z zd dlZW n ey   dZY nw 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parquetpyarrow.pandas_compatr   is_data_framepaTablefrom_pandaswrite_table)tablepathkwargspqr    r   ]/var/www/html/Persson_Maskin/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   
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   BufferOutputStreamr   BufferReadergetvaluer   )r   read_table_kwargswrite_table_kwargswriterreaderr   r   r   _roundtrip_table1   s   r   c                 K   sp   |d u r| }|p	i }t | ||d}|j|jksJ ||s J t |||d}|j|jks/J ||s6J d S )N)r   r   )r   schemaequals)r   expectedr   r   resultr   r   r   _check_roundtrip<   s   r$   c                 C   s    t j| }t||d}| S )N)r   )r   r	   r
   r   	to_pandas)dfwrite_kwargsr   r#   r   r   r   _roundtrip_pandas_dataframeN   s
   r(   c                 C   s<   t d}t |}t jjt|j|jt|j|j| |dS )Nint_sizedtype)npiinforandomrandintmaxmin)r+   r,   platform_int_infor.   r   r   r   _random_integersU   s   

r4   c                 C   s   t tj| |dS )Nr,   )r   arrayr-   aranger*   r   r   r   _range_integers^   s   r8   '  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   r5   c                 S   s   g | ]}t d qS )
   )r   rands).0ir   r   r   
<listcomp>r   s    z#_test_dataframe.<locals>.<listcomp>)uint8uint16uint32uint64int8int16int32int64float32float64boolstringsall_noneall_none_category)pandasr-   r/   seed	DataFramer4   r?   r@   rA   rB   rC   rD   rE   rF   randnastyperG   r7   rH   range)r+   rN   pdr&   r   r   r   _test_dataframeb   s&   







rT   c                 C   sV   dd l m} t| tjr| }ntj| }t }t||ddd |	d |
|S )Nr   SNAPPYz2.6)compressionversion)r   r   
isinstancer   r	   r
   ioBytesIOr   seekParquetFile)table_or_dfr   a_tablebufr   r   r   make_sample_file|   s   

r`   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| 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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   r?   r5   r@   rA   rB   rC   rD   rE   rF   float16rG   rH   rI   datetime_msz2016-01-01T00:00:00.001zdatetime64[ms]datetime_usz2016-01-01T00:00:00.000001zdatetime64[us]datetime_nsz2016-01-01T00:00:00.000000001zdatetime64[ns]	timedeltaztimedelta64[s]strc                 S      g | ]}t |qS r   rf   r<   xr   r   r   r>          z#alltypes_sample.<locals>.<listcomp> c                 S   rg   r   rh   ri   r   r   r   r>      rk      c                 S   s   g | ]	}d g|d  qS )N   r   ri   r   r   r   r>      s    )	empty_strstr_with_nullsnull	null_listcategorystr_category)rM   r-   r/   rN   r7   r?   r@   rA   rB   rD   rE   rF   ra   rG   rH   rP   SeriesrR   rQ   rO   )r+   rN   categoricalrS   arraysr   r   r   alltypes_sample   sf   	



 
rx   )NN)r9   r   )r9   r   F)rY   numpyr-   ImportErrorpyarrowr   pyarrow.testsr   r   r   r   r$   r(   r4   r8   rT   r`   rx   r   r   r   r   <module>   s(   

	
