o
    d=1                     @   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
m  m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d	 Zed
ejddgddied
ejg dddied
ejdddejdddgied
ejdddejdddgied
ej gd i!e"dej gZ#dd Z$dd Z%dd Z&d d! Z'd"d# Z(d$d% Z)ej*d&d'd(d)d* Z+ej*d&d'd(d+d, Z,ej*d&d'd(e	j-.d-e#d.d/ Z/ej*d&d'd(d0d1 Z0ej*d&d'd(d2d3 Z1d4d5 Z2dS )6z test orc compat     N)Decimal)BytesIO)read_orc)StringArrayzpyarrow.orcc                 C   s   | dddS )NiodataZorc )datapathr   r   L/app/.heroku/python/lib/python3.10/site-packages/pandas/tests/io/test_orc.pydirpath   s   r   Zunimpl      Zuint64dtype)abr   category   )leftright   z
2022-01-03D)freqz
2022-01-042   floatc                 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)pd	DataFrameZ
RangeIndexzipSeriesospathjoinr   tmassert_equal)r   r(   ZdtypesexpectedZcolnamer   	inputfilegotr   r   r
   test_orc_reader_empty0   s   r5   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_dictr-   r.   r/   r   keysr0   r1   r   r   r2   r3   r4   r   r   r
   test_orc_reader_basicQ   s   rH   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
   )rC   rD   r   r)   r*   rE   r-   r.   r/   r   ilocr0   r1   rG   r   r   r
   test_orc_reader_decimale   s&   rK   c                 C      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.orcrI   rC   rD   datetimerR   r)   r*   rE   r-   r.   r/   r   rJ   r0   r1   rG   r   r   r
   test_orc_reader_date_low   .    rU   c                 C   rL   )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.100900rM   r   i  rN   rO   r%   rP   zTestOrcFile.testDate2038.orcrI   rS   rG   r   r   r
   test_orc_reader_date_high   rV   rW   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.orcrI   )rC   rD   r)   r*   rE   r-   r.   r/   r   rJ   r0   r1   rG   r   r   r
   !test_orc_reader_snappy_compressed   s    rX   pyarrowz7.0.0)min_versionc                 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 }|| t|}t	|| W d    d S 1 spw   Y  d S NFTr   r   r   r6   r   r7   r8   r    r9   r!   r:   r"   r;   r<   r#   r=   r>   r$   r?   r@   r%   rA   rB   r   )
rC   rD   r)   r*   rE   r0   ensure_cleanto_orcr   r1   )r   r   r2   r.   r4   r   r   r
   test_orc_roundtrip_file   s    

"r^   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t|}t	|| d S r[   )
rC   rD   r)   r*   rE   r]   r   r   r0   r1   )r   r2   bytesr4   r   r   r
   test_orc_roundtrip_bytesio  s   r`   df_not_supportedc                 C   s@   d}t jt|d |   W d    d S 1 sw   Y  d S )Nz6The dtype of one or more columns is not supported yet.match)pytestraisesNotImplementedErrorr]   )ra   msgr   r   r
   $test_orc_writer_dtypes_not_supported*  s   
"rh   c                     s   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 )Nabcr   cr   Nrj   )s   foos   barNr            @      @r$   r   r<         @TFTTFNZ20130101   )ZperiodsZ20130103)stringstring_with_nanstring_with_noner_   intr   float_with_nanr   bool_with_narT   Zdatetime_with_natrY   Zdtype_backendc              	      s(   i | ]}|t jtj | d dqS )T)Zfrom_pandas)r)   ZarraysZArrowExtensionArrayparD   ).0coldfr   r
   
<dictcomp>N  s    z2test_orc_dtype_backend_pyarrow.<locals>.<dictcomp>)r)   r*   listrC   nanrangearangeZ
date_range	TimestampZNaTcopyr]   r   r   r(   r0   assert_frame_equal)
bytes_dataresultr2   r   r}   r
   test_orc_dtype_backend_pyarrow4  s2   


r   c                  C   s  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 )Nri   r   rj   rk   r   rl   rr   ZInt64r   rm   rn   r$   r<   ro   rp   rq   )
rs   rt   ru   rv   Zint_with_nanZna_onlyr   rw   r   rx   Znumpy_nullablery   )r   r   rj   )r   r   rr   )rm   g      @g      @ZFloat64booleanTF)r)   r*   r   rC   r   r   r,   ZNAr   r   r]   r   r   r   rD   Zobject_r0   r   )r~   r   r   r2   r   r   r
   %test_orc_dtype_backend_numpy_nullableW  sB   

r   c               	   C   s   d} t dttddi}td3}|| tjt	| d t
|dd W d    n1 s1w   Y  W d    d S W d    d S 1 sIw   Y  d S )	NzPdtype_backend numpy is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.rv   r   rl   ztmp.orcrb   numpyry   )r)   r*   r   r   r0   r\   r]   rd   re   
ValueErrorr   )rg   r~   r.   r   r   r
   test_invalid_dtype_backend  s   
"r   )3__doc__rT   decimalr   r   r   r-   r   rC   rd   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr)   r   Zpandas._testingZ_testingr0   Zpandas.core.arraysr   ZimportorskiprY   rz   Zfixturer   r*   rD   r,   ZIntervalZPeriodr   ZastypeZSparseDtypeZorc_writer_dtypes_not_supportedr5   rH   rK   rU   rW   rX   Z
skip_if_nor^   r`   markZparametrizerh   r   r   r   r   r   r   r
   <module>   s`    

$!)))


"
*