a
    d                      @   sl   d Z ddlZddlZddlZddlmZ ddl	m
Z
mZ ddlmZmZ edZejjG dd dZdS )z test feather-format compat     N)ArrowStringArrayStringArray)read_feather
to_featherpyarrowc                   @   s   e Zd Zdd Zdd Zdi f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ejjejjdd Zdd Zd d! Zd"d# Zd$d% ZdS )&TestFeatherc              	   C   sd   t j||dB t }t|| W d    n1 s80    Y  W d    n1 sV0    Y  d S )Nmatch)pytestraisestmensure_cleanr   )selfdfexcerr_msgpath r   e/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pandas/tests/io/test_feather.pycheck_error_on_write   s    
z TestFeather.check_error_on_writec              	   C   s`   t tB t  }t|| W d    n1 s40    Y  W d    n1 sR0    Y  d S N)r   Zexternal_error_raised	Exceptionr   r   )r   r   r   r   r   r   check_external_error_on_write   s    
z)TestFeather.check_external_error_on_writeNc                 K   sj   |d u r|  }t >}t||fi | t|fi |}t|| W d    n1 s\0    Y  d S r   )copyr   r   r   r   assert_frame_equal)r   r   expectedwrite_kwargsZread_kwargsr   resultr   r   r   check_round_trip#   s    
zTestFeather.check_round_tripc                 C   sD   d}t g dddt dtg dfD ]}| |t| q,d S )Nz'feather only support IO with DataFrames         r    Zfoo20130101)pdSeries	Timestampnparrayr   
ValueError)r   msgobjr   r   r   
test_error.   s    zTestFeather.test_errorc                 C   s<  t tdttddtdddtjddd	d
dtjdgg ddtjdgt tdt j	tt j
dddd dt j	tt j
ddddd dt dt jt dgt j	tt j
ddddd dd}t jdddd|d< t jddd|d< t ddd|d< |jjjjdksJ | }d |jd < | j||d! d S )"Nabcr       r"      u1g      @g      @float64dtypeg      ?TFTTFr#   )periods)freqz
US/Eastern)r5   tzZ20130103ns)r5   r6   )stringintZuintfloatZfloat_with_nullboolbool_with_nullcatdtdttzZdt_with_nullZdtnsZ2013M)r6   r5   r5   z1 dayZ
timedeltasr   Z	intervals)r    r=   )r   )r$   	DataFramelistranger'   arangeZastypenanZCategoricalZDatetimeIndexZ
date_ranger&   ZNaTZperiod_rangeZtimedelta_rangeZinterval_ranger@   r3   r7   zoner   locr   r   r   r   r   r   r   
test_basic9   s@    


zTestFeather.test_basicc                 C   s2   t jtdddtdd }| | d S )N   r.   r"   Zaaacolumns)r$   rB   r'   rE   ZreshaperC   r   r   r   r   r   r   r   test_duplicate_columns_   s    $z"TestFeather.test_duplicate_columnsc              	   C   sP   t tdttddtdttddd}ddg}| j||| |d	 d S )
Nr-   r    r.   Zxyz   )col1Zcol2col3Zcol4rQ   rR   )r   rM   )r$   rB   rC   rD   r   )r   r   rM   r   r   r   test_read_columnse   s    zTestFeather.test_read_columnsc                 C   sB   t ddgddgddgd}|dd	g }| j||dd	gd
 d S )Nr    r!   xyTF)ABCrW   rV   rL   )r$   rB   r   rI   r   r   r   !test_read_columns_different_orderr   s    z-TestFeather.test_read_columns_different_orderc                 C   s    t dg di}| | d S )Na)rZ   r           @)r$   rB   r   rN   r   r   r   test_unsupported_otherx   s    z"TestFeather.test_unsupported_otherc                 C   s4   t dtdi}| j|dd | j|dd d S )NrV   i T)Zuse_threadsF)r$   rB   r'   rE   r   rN   r   r   r   test_rw_use_threads}   s    zTestFeather.test_rw_use_threadsc                 C   s*   t   }t |jt}t || d S r   )r   makeDataFramereset_indexZround_trip_pathlibr   r   r   r   r   r   r   r   r   test_path_pathlib   s    zTestFeather.test_path_pathlibc                 C   s*   t   }t |jt}t || d S r   )r   r^   r_   Zround_trip_localpathr   r   r   r`   r   r   r   test_path_localpath   s    zTestFeather.test_path_localpathc                 C   s"   t   }| j|ddid d S )Nversionr    )r   )r   r^   r_   r   rN   r   r   r   test_passthrough_keywords   s    z%TestFeather.test_passthrough_keywordsc                 C   s\   t |}t|d*}|j| d t |j}W d    n1 sB0    Y  t|| d S )Nrb)content)r   openZserve_contentreadurlr   r   )r   Zfeather_fileZ
httpserverr   fresr   r   r   test_http_path   s
    (zTestFeather.test_http_pathc                    s  t dttjdtjdgddtjg dddtjdtjdgd	dtjg d
d	dg dg dg dg dd}|dkrttjg dtj	d}ttjddtj
gtj	d}n$tg d}tg d}t T}t|| td| t||d}W d    n1 s0    Y  W d    n1 s<0    Y  ttjdtjd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tjg ddd||d|dkrddlm  t fddjD t| d S )Nr   r    r"   ZInt64r2   r         ?      @ZFloat64)rm   r[   rn   )TFNr4   )rZ   bc)rZ   ro   N)rZ   ro   rp   derj   ghpythonrZ   ro   zmode.string_storagedtype_backendTFbooleanr   )ArrowExtensionArrayc                    s$   i | ]}| j | d dqS )T)Zfrom_pandas)r(   ).0colry   r   par   r   
<dictcomp>   s   z?TestFeather.test_read_feather_dtype_backend.<locals>.<dictcomp>)r
   importorskipr$   rB   r%   r'   rF   r   r(   Zobject_ZNAr   r   r   r   option_contextr   Zpandas.arraysry   rM   r   )r   Zstring_storagerw   r   Zstring_arrayZstring_array_nar   r   r   r|   r   test_read_feather_dtype_backend   sP    


L
z+TestFeather.test_read_feather_dtype_backendc                 C   s2   t jdg dit jg dddd}| | d S )NrZ   r   )r"   r.      test)name)index)r$   rB   Indexr   rN   r   r   r   test_int_columns_and_index   s    $z&TestFeather.test_int_columns_and_indexc              	   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.r:   r    r.   ztmp.featherr   numpyrv   )r$   rB   rC   rD   r   r   r   r
   r   r)   r   )r   r*   r   r   r   r   r   test_invalid_dtype_backend   s    
z&TestFeather.test_invalid_dtype_backendc                 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d	}t|| d S )
Nztest_string_inference.prZ   rT   rU   )datazfuture.infer_stringTzstring[pyarrow_numpy])r   r3   )r$   rB   r   r   r   r   r   )r   Ztmp_pathr   r   r   r   r   r   r   test_string_inference   s    
&z!TestFeather.test_string_inference)__name__
__module____qualname__r   r   r   r,   rJ   rO   rS   rY   r\   r]   ra   rb   rd   r
   marknetwork
single_cpurl   r   r   r   r   r   r   r   r   r      s(   &6r   )__doc__r   r'   r
   Zpandasr$   Zpandas._testingZ_testingr   Zpandas.core.arraysr   r   Zpandas.io.feather_formatr   r   r   r   r   r   r   r   r   r   r   <module>   s   
