a
    ï½„g$  ã                   @   sx   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j d¡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_featherz=ignore:Passing a BlockManager to DataFrame:DeprecationWarningÚ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   ú_/home/yuhw/wc/wire-cell-python/wcpy/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_error2   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      @Zfloat64©Údtypeg      ð?©TFTTFr#   )Úperiods)Úfreqz
US/Eastern)r4   ÚtzZ20130103Úns)r4   r5   )ÚstringÚintZuintÚfloatZfloat_with_nullÚboolÚbool_with_nullÚcatÚdtÚdttzZdt_with_nullZdtnsZ2013ÚM)r5   r4   r4   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?   r2   r6   Úzoner   Úlocr   ©r   r   r   r   r   r   Ú
test_basic=   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$   rA   r'   rD   ÚreshaperB   r   r   ©r   r   r   r   r   Útest_duplicate_columnsc   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   rL   )r$   rA   rB   rC   r   )r   r   rL   r   r   r   Útest_read_columnsi   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   rK   )r$   rA   r   rH   r   r   r   Ú!test_read_columns_different_orderv   s    z-TestFeather.test_read_columns_different_orderc                 C   s    t  dg d¢i¡}|  |¡ d S )NÚa)rZ   r    ç       @)r$   rA   r   rN   r   r   r   Útest_unsupported_other|   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$   rA   r'   rD   r   rN   r   r   r   Útest_rw_use_threads�   s    zTestFeather.test_rw_use_threadsc                 C   sh   t jdt d¡ d¡ t jtdƒtd�t jdd„ tdƒD ƒtd�d	� 	¡ }t
 |jt¡}t
 ||¡ d S )
Nçš™™™™™ñ?éx   ©é   r.   ÚABCDr1   c                 S   s   g | ]}d |› �‘qS ©zi-r   ©Ú.0Úir   r   r   Ú
<listcomp>Š   ó    z1TestFeather.test_path_pathlib.<locals>.<listcomp>ra   ©rL   Úindex)r$   rA   r'   rD   rM   ÚIndexrB   ÚobjectrC   Úreset_indexr   Zround_trip_pathlibr   r   r   ©r   r   r   r   r   r   Útest_path_pathlib†   s    ý
zTestFeather.test_path_pathlibc                 C   sh   t jdt d¡ d¡ t jtdƒtd�t jdd„ tdƒD ƒtd�d	� 	¡ }t
 |jt¡}t
 ||¡ d S )
Nr^   r_   r`   rb   r1   c                 S   s   g | ]}d |› �‘qS rc   r   rd   r   r   r   rg   “   rh   z3TestFeather.test_path_localpath.<locals>.<listcomp>ra   ri   )r$   rA   r'   rD   rM   rk   rB   rl   rC   rm   r   Zround_trip_localpathr   r   r   rn   r   r   r   Útest_path_localpath�   s    ý
zTestFeather.test_path_localpathc                 C   s`   t jdt d¡ d¡ t jtdƒtd�t jdd„ tdƒD ƒtd�d	� 	¡ }| j
|d
did� d S )Nr^   r_   r`   rb   r1   c                 S   s   g | ]}d |› �‘qS rc   r   rd   r   r   r   rg   œ   rh   z9TestFeather.test_passthrough_keywords.<locals>.<listcomp>ra   ri   Úversionr    )r   )r$   rA   r'   rD   rM   rk   rB   rl   rC   rm   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                    s4  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rªttjg d¢tjd�ƒ}ttjddt jgtjd�ƒ}n^|dkräddl	m
‰  ˆ t g d¢¡ƒ}ˆ t g d¢¡ƒ}n$tt g d¢¡ƒ}tt g d¢¡ƒ}t ¡ �T}t||ƒ t  d|¡� t||d�}W d   ƒ n1 �sL0    Y  W d   ƒ n1 �sl0    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�r$ddl	m
‰  t  ‡ ‡fdd„ˆjD ƒ¡‰t |ˆ¡ d S )Nr    r"   ZInt64r1   r   ç      ø?ç      @ZFloat64)r{   r[   r|   )TFNr3   )rZ   ÚbÚc)rZ   r}   N)rZ   r}   r~   ÚdÚerx   ÚgÚhÚpythonrZ   r}   r   r   )ÚArrowExtensionArrayzmode.string_storage©Údtype_backendTFÚbooleanc                    s$   i | ]}|ˆ t jˆ| d d�ƒ“qS )T)Zfrom_pandas)Úpar(   )re   Úcol©r„   r   r   r   Ú
<dictcomp>Ý   s   ÿz?TestFeather.test_read_feather_dtype_backend.<locals>.<dictcomp>)r$   rA   r%   r'   rE   r   r(   Zobject_ZNAZpandas.arraysr„   rˆ   r   r   r   r   Úoption_contextr   rL   r   )r   Zstring_storager†   r   Zstring_arrayZstring_array_nar   r   r   rŠ   r   Útest_read_feather_dtype_backendª   sV    øÿ

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)rj   )r$   rA   rk   r   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 s€0    Y  d S )	NzPdtype_backend numpy is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.r9   r    r.   ztmp.featherr   Únumpyr…   )r$   rA   rB   rC   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”   r2   )r$   rA   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,   rI   rO   rS   rY   r\   r]   ro   rp   rr   r
   ÚmarkÚnetworkÚ
single_cpurz   r�   r‘   r“   r•   r   r   r   r   r      s(   &		;r   )Ú__doc__r’   r'   r
   Zpandasr$   Zpandas._testingZ_testingr   Zpandas.core.arraysr   r   Zpandas.io.feather_formatr   r   r™   ÚfilterwarningsZ
pytestmarkZimportorskiprˆ   r›   r   r   r   r   r   Ú<module>   s   ÿ
