o
    i                     @   s|   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 ejdddZejdZeejjejdG d	d
 d
ZdS )z test feather-format compat     N)read_feather
to_featherpyarrowz1.0.1)
minversionzignore:The Sparsez8ignore:CategoricalBlock is deprecated:DeprecationWarningc                   @   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dd Zdd Zejjejd 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   W/var/www/edux/Edux_v2/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   sh   |d u r|}t   }t||fi | t|fi |}t || W d    d S 1 s-w   Y  d S r   )r
   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_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sJ | | d S ) Nabcr      r!      u1g      @g      @float64)dtypeg      ?)TFTTFr#   periods)freqz
US/Eastern)r4   tz20130103ns)r4   r5   )stringintuintfloatfloat_with_nullboolbool_with_nullcatdtdttzdt_with_nulldtns2013M)r5   r4   r4   z1 day
timedeltasr   	intervals)r$   	DataFramelistranger'   arangeastypenanCategoricalDatetimeIndex
date_ranger&   NaTperiod_rangetimedelta_rangeinterval_rangerB   r2   r6   zoner   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!   aaacolumns)r$   rI   r'   rL   reshaperJ   copyr   rW   r   r   r   test_duplicate_columns_   s   $z"TestFeather.test_duplicate_columnsc                 C   s2   t tddd }d}| |t| d S )NrY   r.   r!   %feather must have string column names)r$   rI   r'   rL   r]   r^   r   r)   )r   r   r*   r   r   r   test_stringify_columnsf   s   z"TestFeather.test_stringify_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.   xyz   )col1col2col3col4rd   rf   )r   r\   )r$   rI   rJ   rK   r   )r   r   r\   r   r   r   test_read_columnsl   s   zTestFeather.test_read_columnsc                 C   s4   t ddgddgddgd}| j|dd	gd
 d S )Nr   r    xyTF)ABCrl   rk   r[   )r$   rI   r   rW   r   r   r   read_columns_different_ordery   s   z(TestFeather.read_columns_different_orderc                 C   s    t dg di}| | d S )Na)ro   r   g       @)r$   rI   r   rW   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 )Nrk   i T)use_threadsF)r$   rI   r'   rL   r   rW   r   r   r   test_rw_use_threads   s   zTestFeather.test_rw_use_threadsc                 C   s   t dg di}| | d}g dt jdddtdg d	t jg d
fD ]}||_| |t	| q(g d|_d|j_
d}| |t	| g d|_t jdg|_d}| |t	| d S )Nrk   r   zsfeather does not support serializing .* for the index; you can \.reset_index\(\) to make the index into column\(s\))r    r!   r.   r#   r!   r3   r-   )r   r!   r.   )ro   r   )ro   r    )br   )r   r   r    r"   z=feather does not serialize index meta-data on a default indexrs   r`   )r$   rI   r   rQ   rJ   
MultiIndexfrom_tuplesindexr   r)   namer\   )r   r   r*   rw   r   r   r   test_write_with_index   s(   


z!TestFeather.test_write_with_indexc                 C   *   t   }t |jt}t || d S r   )r
   makeDataFramereset_indexround_trip_pathlibr   r   r   r   r   r   r   r   r   test_path_pathlib      zTestFeather.test_path_pathlibc                 C   rz   r   )r
   r{   r|   round_trip_localpathr   r   r   r~   r   r   r   test_path_localpath   r   zTestFeather.test_path_localpathc                 C   s"   t   }| j|ddid d S )Nversionr   )r   )r
   r{   r|   r   rW   r   r   r   test_passthrough_keywords   s   z%TestFeather.test_passthrough_keywordskhttps://raw.githubusercontent.com/pandas-dev/pandas/main/pandas/tests/io/data/feather/feather-0_3_1.featherT)urlcheck_before_testc                 C   s$   d}t |}t |}t|| d S )Nr   )r   r
   r   )r   feather_filer   r   resr   r   r   test_http_path   s
   zTestFeather.test_http_path)__name__
__module____qualname__r   r   r   r,   rX   r_   ra   rh   rn   rp   rr   ry   r   r   r   r   marknetworkr
   r   r   r   r   r   r      s,    $!r   )__doc__numpyr'   r   pandasr$   pandas._testing_testingr
   pandas.io.feather_formatr   r   importorskipr   r   filterwarningsfilter_sparse
single_cpur   r   r   r   r   <module>   s    
