o
    vh'                     @   sx   d Z ddlZddlZddlmZmZ ddlZddl	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)pa_version_under18p0pa_version_under19p0)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ejjed&d'd(d) ZdS )*TestFeatherc              	   C   sv   t j||d* t }t|| W d    n1 sw   Y  W d    d S W d    d S 1 s4w   Y  d S )Nmatch)pytestraisestmensure_cleanr   )selfdfexcerr_msgpath r   Z/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/pandas/tests/io/test_feather.pycheck_error_on_write   s   
"z TestFeather.check_error_on_writec              	   C   sr   t t* t  }t|| W d    n1 sw   Y  W d    d S W d    d S 1 s2w   Y  d S N)r   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   sl   |d u r|  }t  }t||fi | t|fi |}t|| W d    d S 1 s/w   Y  d S r   )copyr   r   r   r   assert_frame_equal)r   r   expectedwrite_kwargs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"   foo20130101)pdSeries	Timestampnparrayr   
ValueError)r   msgobjr   r   r   
test_error4   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sJ | }d |jd < | j||d! d S )"Nabcr"      r$      u1g      @g      @float64dtypeg      ?TFTTFr&   )periods)freqz
US/Eastern)r8   tz20130103ns)r8   r9   )stringintuintfloatfloat_with_nullboolbool_with_nullcatdtdttzdt_with_nulldtns2013M)r9   r8   r8   z1 day
timedeltasr   	intervals)r"   rC   )r   )r'   	DataFramelistranger*   arangeastypenanCategoricalDatetimeIndex
date_ranger)   NaTperiod_rangetimedelta_rangeinterval_rangerF   r6   r:   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   r1   r$   aaacolumns)r'   rM   r*   rP   reshaperN   r   r   r   r   r   r   r   test_duplicate_columnse   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 )
Nr0   r"   r1   xyz   )col1col2col3col4rg   ri   )r   ra   )r'   rM   rN   rO   r    )r   r   ra   r   r   r   test_read_columnsk   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Cro   rn   r`   )r'   rM   r    r\   r   r   r   !test_read_columns_different_orderx   s   z-TestFeather.test_read_columns_different_orderc                 C   s    t dg di}| | d S )Na)rr   r"          @)r'   rM   r   rc   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 )Nrn   i T)use_threadsF)r'   rM   r*   rP   r    rc   r   r   r   test_rw_use_threads   s   zTestFeather.test_rw_use_threadsc                 C   `   t jdtdd t tdt dd tdD d }t	
|jt}t	|| d S )	N皙?x      r1   ABCDc                 S      g | ]}d | qS zi-r   .0ir   r   r   
<listcomp>       z1TestFeather.test_path_pathlib.<locals>.<listcomp>r{   ra   index)r'   rM   r*   rP   rb   IndexrN   rO   reset_indexr   round_trip_pathlibr   r   r   r   r   r   r   r   r   test_path_pathlib      zTestFeather.test_path_pathlibc                 C   rw   )	Nrx   ry   rz   r|   c                 S   r}   r~   r   r   r   r   r   r      r   z3TestFeather.test_path_localpath.<locals>.<listcomp>r{   r   )r'   rM   r*   rP   rb   r   rN   rO   r   r   round_trip_localpathr   r   r   r   r   r   r   test_path_localpath   r   zTestFeather.test_path_localpathc                 C   sX   t jdtdd t tdt dd tdD d }| j	|d	d
id d S )Nrx   ry   rz   r|   c                 S   r}   r~   r   r   r   r   r   r      r   z9TestFeather.test_passthrough_keywords.<locals>.<listcomp>r{   r   versionr"   )r   )
r'   rM   r*   rP   rb   r   rN   rO   r   r    rc   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 s!w   Y  t|| d S )Nrb)content)r   openserve_contentreadurlr   r   )r   feather_file
httpserverr   fresr   r   r   test_http_path   s   zTestFeather.test_http_pathc                    s  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}t )}t|| t d| t	||d}W d    n1 sWw   Y  W d    n1 sfw   Y  |dkrt
d|r~t  }nt  }nt |}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t jg d|dt jg d|dd|dkrddlm  t  fddjD |rjt j|tjd_t| d S )Nr"   r$   Int64r5   r!         ?      @Float64)r   rs   r   )TFNr7   )rr   bc)rr   r   N)rr   r   r   der   ghzmode.string_storagedtype_backendr   TFbooleanr   )ArrowExtensionArrayc                    s$   i | ]}| j | d dqS )T)from_pandas)r+   )r   colr   r   par   r   
<dictcomp>   s    z?TestFeather.test_read_feather_dtype_backend.<locals>.<dictcomp>na_value)r'   rM   r(   r*   rR   r   r   r   option_contextr   r
   importorskip
ArrowDtypelarge_stringr=   StringDtypeNApandas.arraysr   ra   rQ   r   )r   string_storager   using_infer_stringr   r   r   string_dtyper   r   r   test_read_feather_dtype_backend   s^   



z+TestFeather.test_read_feather_dtype_backendc                 C   s2   t jdg dit jg dddd}| | d S )Nrr   r!   )r$   r1      test)name)r   )r'   rM   r   r    rc   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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.r>   r"   r1   ztmp.featherr   numpyr   )r'   rM   rN   rO   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 s(w   Y  t jtjd}t jdddgit jtjdd	}t jdddgi|t jdgt	rV|sVt
n|d
d}t|| d S )Nztest_string_inference.prr   rl   rm   )datafuture.infer_stringTr   r   r6   r5   )r   r6   ra   )r'   rM   r   r   r   r   r*   rR   r   r   objectr   r   )r   tmp_pathr   r   r   r   r6   r   r   r   r   test_string_inference   s.   



z!TestFeather.test_string_inferenceznot supported before 18.0)reasonc                 C   s   dd l }ddl m} |d }|d|g d| i}||| tdd t|}tj	dg ditj
tjdd	}W d    n1 sHw   Y  t|| d S )
Nr   )featherzstring_view.parquetrr   )Nr   r   r   Tr   r   )r   r   tabler+   string_viewwrite_featherr'   r   r   rM   r   r*   rR   r   r   )r   r   r   r   r   r   r   r   r   r   r   &test_string_inference_string_view_type  s   z2TestFeather.test_string_inference_string_view_type)__name__
__module____qualname__r   r   r    r/   r]   rd   rk   rq   rt   rv   r   r   r   r
   marknetwork
single_cpur   r   r   r   r   skipifr   r   r   r   r   r   r      s.    &		<r   )__doc__r   r*   r
   pandas.compat.pyarrowr   r   pandasr'   pandas._testing_testingr   pandas.io.feather_formatr   r   r   filterwarnings
pytestmarkr   r   r   r   r   r   r   r   <module>   s    
