U
    f/eN                     @   s   d 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mZ e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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
ejddd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dejd$d% ZdS )&TestFeatherc              
   C   s<   t j||d$ t }t|| W 5 Q R X W 5 Q R X d S )N)match)pytestZraisestmensure_cleanr   )selfdfexcerr_msgpath r   @/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/io/test_feather.pycheck_error_on_write   s    
z TestFeather.check_error_on_writec              
   C   s8   t t$ t  }t|| W 5 Q R X W 5 Q R X 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 kr|}t  ,}t||f| t|f|}t || W 5 Q R X d S r   )r   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   sH   d}t dddgddt dtdddgfD ]}| |t| q0d S )Nz'feather only support IO with DataFrames         foo20130101)pdZSeries	Timestampnparrayr   
ValueError)r
   msgobjr   r   r   
test_error1   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dddg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< |jjjjdkst| | d S )Nabcr      r      u1g      @g      @Zfloat64)dtypeg      ?TFr   periods)freqz
US/Eastern)r-   tzZ20130103ns)r-   r.   )stringintZuintfloatZfloat_with_nullboolZbool_with_nullcatdtdttzZdt_with_nullZdtnsZ2013M)r.   r-   r-   z1 dayZ
timedeltas)r   	DataFramelistranger!   arangeZastypenanZCategoricalZDatetimeIndex
date_ranger    ZNaTZperiod_rangeZtimedelta_ranger7   r+   r/   zoneAssertionErrorr   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   r9   r!   r<   reshaper:   copyr   rA   r   r   r   test_duplicate_columnsc   s    $z"TestFeather.test_duplicate_columnsc                 C   s2   t tddd }d}| |t| d S )NrC   r(   r   %feather must have string column names)r   r9   r!   r<   rF   rG   r   r#   )r
   r   r$   r   r   r   test_stringify_columnsj   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(   Zxyz   )col1Zcol2col3Zcol4rL   rM   )r   rE   )r   r9   r:   r;   r   )r
   r   rE   r   r   r   test_read_columnsp   s    zTestFeather.test_read_columnsr   z0.17.1)min_versionc                 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CrS   rR   rD   )r   r9   r   rA   r   r   r   read_columns_different_order}   s    z(TestFeather.read_columns_different_orderc                 C   s"   t ddddgi}| | d S )Nar   g       @)r   r9   r   rA   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 )NrR   i T)Zuse_threadsF)r   r9   r!   r<   r   rA   r   r   r   test_rw_use_threads   s    zTestFeather.test_rw_use_threadsc              	   C   s   t ddddgi}| | d}dddgt jdddtd	dddgt jd
ddgfD ]}||_| |t	| qXdddg|_d|j_
d}| |t	| dddg|_t jd
g|_d}| |t	| d S )NrR   r   r   r   zsfeather does not support serializing .* for the index; you can \.reset_index\(\) to make the index into column\(s\)r(   r   r,   r'   )rV   r   )rV   r   )br   r   r   z=feather does not serialize index meta-data on a default indexrI   )r   r9   r   r>   r:   Z
MultiIndexfrom_tuplesindexr   r#   namerE   )r
   r   r$   r[   r   r   r   test_write_with_index   s(    
z!TestFeather.test_write_with_indexc                 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_localpathz0.17.0c                 C   s"   t   }| j|ddid d S )Nversionr   )r   )r   r^   r_   r   rA   r   r   r   test_passthrough_keywords   s    z%TestFeather.test_passthrough_keywordsc                 C   s$   d}t |}t |}t|| d S )Nzmhttps://raw.githubusercontent.com/pandas-dev/pandas/master/pandas/tests/io/data/feather/feather-0_3_1.feather)r   r   r   )r
   Zfeather_fileurlr   resr   r   r   test_http_path   s
    zTestFeather.test_http_path)__name__
__module____qualname__r   r   r   r&   rB   rH   rJ   rN   tdZ
skip_if_norU   rW   rX   r]   ra   rb   rd   r   networkrg   r   r   r   r   r      s(   &
!
r   )__doc__Znumpyr!   r   Zpandas.util._test_decoratorsutilZ_test_decoratorsrk   Zpandasr   Zpandas._testingZ_testingr   Zpandas.io.feather_formatr   r   Zimportorskipr   markfilterwarningsZfilter_sparseZsingler   r   r   r   r   <module>   s   

