a
    Pf_5                  
   @   s  d Z ddlZddlmZ ddlmZ ddlZddlZddlZ	ddl
Z
ddlZddlmZ ddlmZ ddlmZ e
d ddlZe
jdZe
jd	d
 Ze
je	jddgddejg dddejdddejdddgejdddejdddggddd Zdd Z dd Z!dd  Z"d!d" Z#d#d$ Z$d%d& Z%d'd( Z&d)d* Z'd+d, Z(d-d. Z)d/d0 Z*d1d2 Z+e
j,d3ej-dddd4ej-dd5dd6d7e.g d8gd9d: Z/d;d< Z0d=d> Z1dS )?z test orc compat     N)Decimal)BytesIO)read_orc)StringArrayzpyarrow.orcz=ignore:Passing a BlockManager to DataFrame:DeprecationWarningc                 C   s   | dddS )NiodataZorc )datapathr   r   Q/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/io/test_orc.pydirpath   s    r         Zuint64dtype)abr   category   )leftright   z
2022-01-03D)freqz
2022-01-04)paramsc                 C   s   t d| jiS )NZunimpl)pd	DataFrameparam)requestr   r   r
   orc_writer_dtypes_not_supported   s    r   c                 C   sp   g d}g d}t jt dd}t||D ]\}}t j|d||< q,tj| d}t||d}t	
|| d S )N	Zboolean1Zbyte1Zshort1int1Zlong1Zfloat1Zdouble1Zbytes1string1)	boolint8int16int32int64float32float64objectr)   r   indexr   zTestOrcFile.emptyFile.orccolumns)r   r   
RangeIndexzipSeriesospathjoinr   tmassert_equal)r   r-   ZdtypesexpectedZcolnamer   	inputfilegotr   r   r
   test_orc_reader_empty-   s    r9   c                 C   s   t jddgddt jddgddt jdd	gd
dt jddgddt jddgddt jddgddt jddgddt jddgddt jddgddd	}tj|}tj| d}t||	 d}t
|| d S )NFTr"   r   r   d   r#         r$      r%       r&         ?       @r'         .      r(           r)   hibyer   zTestOrcFile.test1.orcr,   )nparrayr   r   	from_dictr1   r2   r3   r   keysr4   r5   r   r   r6   r7   r8   r   r   r
   test_orc_reader_basicN   s    rL   c                 C   s   dt jtdtdtdtdtdtdtdtd	td
tdg
ddi}tj|}tj| d}t	|j
d d }t|| d S )NZ_col0z-1000.50000z
-999.60000z
-998.70000z
-997.80000z
-996.90000z
-995.10000z
-994.11000z
-993.12000z
-992.13000z
-991.14000r)   r   zTestOrcFile.decimal.orc
   )rG   rH   r   r   r   rI   r1   r2   r3   r   ilocr4   r5   rK   r   r   r
   test_orc_reader_decimalb   s&    rO   c                 C   s   t jg dddt jtdddtdddtdddtdddtdddtdddtdddtdddtdddtdddg
ddd}tj|}tj	| d	}t
|jd d
 }t|| d S )N)
z1900-05-05 12:34:56.100000z1900-05-05 12:34:56.100100z1900-05-05 12:34:56.100200z1900-05-05 12:34:56.100300z1900-05-05 12:34:56.100400z1900-05-05 12:34:56.100500z1900-05-05 12:34:56.100600z1900-05-05 12:34:56.100700z1900-05-05 12:34:56.100800z1900-05-05 12:34:56.100900datetime64[ns]r   il        r)   timedatezTestOrcFile.testDate1900.orcrM   rG   rH   datetimerU   r   r   rI   r1   r2   r3   r   rN   r4   r5   rK   r   r   r
   test_orc_reader_date_low}   s.     rX   c                 C   s   t jg dddt jtdddtdddtdddtdddtdddtdddtdddtdddtdddtdddg
ddd}tj|}tj	| d	}t
|jd d
 }t|| d S )N)
z2038-05-05 12:34:56.100000z2038-05-05 12:34:56.100100z2038-05-05 12:34:56.100200z2038-05-05 12:34:56.100300z2038-05-05 12:34:56.100400z2038-05-05 12:34:56.100500z2038-05-05 12:34:56.100600z2038-05-05 12:34:56.100700z2038-05-05 12:34:56.100800z2038-05-05 12:34:56.100900rP   r   i  rQ   rR   r)   rS   zTestOrcFile.testDate2038.orcrM   rV   rK   r   r   r
   test_orc_reader_date_high   s.     rY   c                 C   sb   t jg dddt jg dddd}tj|}tj| d}t|j	d d }t
|| d S )	N)
iEAںijFiA!{i~iY5B
irhi;Sinqi:i(r%   r   )
Zf50dcb8Z382fdaaaZ90758c6Z9e8caf3fZee97332bZd634da1Z2bea4396Zd67d89e8Zad71007eZe8c82066r)   )r    r!   zTestOrcFile.testSnappy.orcrM   )rG   rH   r   r   rI   r1   r2   r3   r   rN   r4   r5   rK   r   r   r
   !test_orc_reader_snappy_compressed   s     rZ   c                 C   s   t d tjddgddtjddgddtjd	d
gddtjddgddtjddgddtjddgddtjddgddtjddgddtjddgddd	}tj|}t .}|	| t
|}t|| W d    n1 s0    Y  d S NpyarrowFTr"   r   r   r:   r#   r;   r<   r$   r=   r%   r>   r&   r?   r@   r'   rA   rB   r(   rC   rD   r)   rE   rF   r   )pytestimportorskiprG   rH   r   r   rI   r4   ensure_cleanto_orcr   r5   )r   r   r6   r2   r8   r   r   r
   test_orc_roundtrip_file   s     


ra   c                  C   s   t d tjddgddtjddgddtjd	d
gddtjddgddtjddgddtjddgddtjddgddtjddgddtjddgddd	} tj| }| }tt	|}t
|| d S r[   )r]   r^   rG   rH   r   r   rI   r`   r   r   r4   r5   )r   r6   bytesr8   r   r   r
   test_orc_roundtrip_bytesio  s    
rc   c                 C   sH   t d d}t jt|d |   W d    n1 s:0    Y  d S )Nr\   z6The dtype of one or more columns is not supported yet.match)r]   r^   raisesNotImplementedErrorr`   )r   msgr   r   r
   $test_orc_writer_dtypes_not_supported)  s    
ri   c                     s   t d ttddtjdgg dg dttddtjd	d
dddtjdgg dg dtj	dddt
dtjt
dgd    } tt| dd}t fdd jD }t|| d S )Nr\   abcr   cr   Nrk   )s   foos   barNr            @      @r(   r   r@         @TFTTFNZ20130101   )ZperiodsZ20130103)stringstring_with_nanstring_with_nonerb   intfloatfloat_with_nanr"   bool_with_narW   Zdatetime_with_natZdtype_backendc              	      s(   i | ] }|t jtj | d dqS )T)Zfrom_pandas)r   ZarraysZArrowExtensionArrayparH   ).0coldfr   r
   
<dictcomp>M  s   z2test_orc_dtype_backend_pyarrow.<locals>.<dictcomp>)r]   r^   r   r   listrG   nanrangearangeZ
date_range	TimestampZNaTcopyr`   r   r   r-   r4   assert_frame_equal)
bytes_dataresultr6   r   r   r
   test_orc_dtype_backend_pyarrow3  s4    



r   c                  C   s  t d ttddtjdgg dttddtjdtj	dgd	d
tjtj	tj	tj	gd	d
tj
dddd
dtjdgg dg dd
} |   }tt|dd}tttjg dtjd
ttjdtj	dgtjd
ttjdtj	dgtjd
tjg dd	d
tjdtj	dgd	d
tjtj	tj	tj	gd	d
tjg ddd
tjdtj	dgdd
tjg ddd
tjddtj	gdd
d
}t|| d S )Nr\   rj   r   rk   rl   r   rm   rs   ZInt64r   rn   ro   r(   r@   rp   rq   rr   )
rt   ru   rv   rw   Zint_with_nanZna_onlyrx   ry   r"   rz   Znumpy_nullabler{   )r   r   rk   r   r   rs   )rn   g      @g      @ZFloat64booleanTF)r]   r^   r   r   r   rG   r   r   r0   ZNAr   r   r`   r   r   r   rH   Zobject_r4   r   )r   r   r   r6   r   r   r
   %test_orc_dtype_backend_numpy_nullableV  sD    


r   c                  C   sr   t dttddi} td0}| | t|	 }t
|}W d    n1 sX0    Y  t||  d S )Nrw   r   rm   tmp.orc)r   r   r   r   r4   r_   r`   pathlibPathas_urir   r   )r6   r2   urir   r   r   r
   test_orc_uri_path  s    
&r   r+   )startstopsteprs   znon-default)r   r   r   namer   c                 C   sT   t jdg di| d}d}tjt|d |  W d    n1 sF0    Y  d S )Nr   r   r*   z[orc does not support serializing a non-default index|orc does not serialize index meta-datard   )r   r   r]   rf   
ValueErrorr`   )r+   r   rh   r   r   r
   test_to_orc_non_default_index  s
    	r   c               	   C   s   d} t dttddi}tdT}|| tjt	| d t
|dd W d    n1 sb0    Y  W d    n1 s0    Y  d S )	NzPdtype_backend numpy is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.rw   r   rm   r   rd   numpyr{   )r   r   r   r   r4   r_   r`   r]   rf   r   r   )rh   r   r2   r   r   r
   test_invalid_dtype_backend  s    
r   c                 C   s   | d }t jdddgid}|| t dd t|}W d    n1 sP0    Y  t jdddgidt jdgdd	d
}t|| d S )Nztest_string_inference.pr   xy)r   zfuture.infer_stringTzstring[pyarrow_numpy]r   )r   r   r-   )r   r   r`   Zoption_contextr   Indexr4   r   )Ztmp_pathr2   r   r   r6   r   r   r
   test_string_inference  s    
&
r   )2__doc__rW   decimalr   r   r   r1   r   r   rG   r]   Zpandasr   r   Zpandas._testingZ_testingr4   Zpandas.core.arraysr   r^   r\   r|   markfilterwarningsZ
pytestmarkZfixturer   rH   r0   ZIntervalZPeriodr   r9   rL   rO   rX   rY   rZ   ra   rc   ri   r   r   r   Zparametrizer.   r   r   r   r   r   r   r   r
   <module>   s`   


!)))
#+	

