a
    ï½„gâ\  ã                   @   s2  d Z ddlZddlZddlmZ ddlmZmZmZ ddl	Z	ddl
Z
ddlmZ ddlZddlZddlZddlZddlmZ ddlm  mZ ddlZddlmZ ddlm  mZ ej  !d¡Z"G dd	„ d	ƒZ#e$e#egZ%zdd
l&m'Z( e% )e(¡ W n e*�y   Y n0 e
j+ ,e
j+ -e.¡¡Z/G dd„ dƒZ0ej1dd„ ƒZ2G dd„ dƒZ3dd„ Z4ej  5dddg¡ej  5dddg¡dd„ ƒƒZ6dd„ Z7ej  5deddfedd fg¡d!d"„ ƒZ8ej  5d#g d$¢¡ej  5dddg¡d%d&„ ƒƒZ9d'd(„ Z:d)d*„ Z;d+d,„ Z<d-d.„ Z=ej  5d/ej>ej?ej@ejAejBejCejDejEejFg	¡d0d1„ ƒZGdS )2z0
Tests for the pandas.io.common functionalities
é    N)Úpartial)ÚBytesIOÚStringIOÚUnsupportedOperation)ÚPath)Úis_platform_windowsz=ignore:Passing a BlockManager to DataFrame:DeprecationWarningc                   @   s&   e Zd ZdZddœdd„Zdd„ ZdS )ÚCustomFSPathz%For testing fspath on unknown objectsN)Úreturnc                 C   s
   || _ d S ©N©Úpath)Úselfr   © r   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pandas/tests/io/test_common.pyÚ__init__%   s    zCustomFSPath.__init__c                 C   s   | j S r
   r   ©r   r   r   r   Ú
__fspath__(   s    zCustomFSPath.__fspath__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   "   s   r   )Úlocalc                   @   s  e Zd ZdZdd„ Zdd„ Zdd„ Ze d¡d	d
„ ƒZ	dd„ Z
dd„ Zej de¡dd„ ƒZej deeeg¡dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zej dejdedfejdedfejd ed!fejd"ed#fej d$ed%fej!ded&fej"ded'fej#ded(fej$ded)fg	¡d*d+„ ƒZ%ej d,ej&j'dedfej&j(ded-fej&j)d ed!fej&j*d"ed#fej&j+d"ed.fej&j,ded&fej&j-ded(fej&j.ded)fg¡d/d0„ ƒZ/ej dejdedfej0dedfejdedfejd ed!fejd"ed#fej d$ed%fej!ded&fej"ded'fej#ded(fej$ded)fg
¡d1d2„ ƒZ1ej d3ejdd4fej0dd4fejdd5fejd d6fejd"d7fej d$d8fej!dd9fej"dd:fej#dd;fej$dd<fg
¡d=d>„ ƒZ2ej d?d@i dfdAdBdCidCfdDi d"fdEi dfdFi dfdGi dfdHi dfdIdJe 3dK¡idfg¡dLdM„ ƒZ4dNdO„ Z5dPS )QÚTestCommonIOCapabilitiesziindex,A,B,C,D
foo,2,3,4,5
bar,7,8,9,10
baz,12,13,14,15
qux,12,13,14,15
foo2,12,13,14,15
bar2,12,13,14,15
c                 C   sB   d}t  |¡}||ksJ ‚tj |¡s*J ‚tj |¡|ks>J ‚d S )Nz
~/sometest)ÚicomÚ_expand_userÚosr   ÚisabsÚ
expanduser©r   ÚfilenameZexpanded_namer   r   r   Útest_expand_userD   s
    
z)TestCommonIOCapabilities.test_expand_userc                 C   s2   d}t  |¡}||ksJ ‚tj |¡|ks.J ‚d S )Nz/somefolder/sometest)r   r   r   r   r   r   r   r   r   Útest_expand_user_normal_pathL   s    
z5TestCommonIOCapabilities.test_expand_user_normal_pathc                 C   sB   t  tdƒ¡}|dksJ ‚t  tdƒ¡}|tj dd¡ks>J ‚d S )NÚ.zfoo//barÚfooÚbar)r   Ústringify_pathr   r   r   Újoin)r   Úrel_pathZredundant_pathr   r   r   Útest_stringify_path_pathlibS   s    z4TestCommonIOCapabilities.test_stringify_path_pathlibzpy.pathc                 C   s8   t j dd¡}t j |¡}t|ƒ}t |¡|ks4J ‚d S )Nr#   r$   )r   r   r&   ÚabspathÚ	LocalPathr   r%   )r   r   Úabs_pathZlpathr   r   r   Útest_stringify_path_localpathY   s    z6TestCommonIOCapabilities.test_stringify_path_localpathc                 C   s"   t dƒ}t |¡}|dksJ ‚d S )Núfoo/bar.csv)r   r   r%   )r   ÚpÚresultr   r   r   Útest_stringify_path_fspath`   s    
z3TestCommonIOCapabilities.test_stringify_path_fspathc              	   C   s|   t  d¡}t ¡ �V}|jd|› �dd��"}|t |¡ks<J ‚W d   ƒ n1 sP0    Y  W d   ƒ n1 sn0    Y  d S )NÚfsspeczfile://Úwb©Úmode)ÚpytestÚimportorskipÚtmÚensure_cleanÚopenr   r%   )r   r1   r   Z
fsspec_objr   r   r   Ú!test_stringify_file_and_path_likee   s    

z:TestCommonIOCapabilities.test_stringify_file_and_path_likeÚ	path_typec                 C   s2   |\}}|d| ƒ}t j|dd�}||ks.J ‚d S )Nr-   Zinfer)Úcompression)r   Zinfer_compression)r   Zcompression_formatr;   Ú	extensionÚexpectedr   r<   r   r   r   Ú test_infer_compression_from_pathl   s    z9TestCommonIOCapabilities.test_infer_compression_from_pathc              	   C   s¢   t jt ¡ d��~}|dt|ƒj d ƒ}t |d¡�<}t|jjƒ ¡ sJJ ‚t	j
 |¡|jjksbJ ‚W d   ƒ n1 sv0    Y  W d   ƒ n1 s”0    Y  d S )N)Údirz~/z	/sometestÚw)ÚtempfileÚTemporaryDirectoryr   ÚhomeÚnamer   Ú
get_handleÚhandleÚis_absoluter   r   r   )r   r;   Útmpr   Úhandlesr   r   r   Útest_get_handle_with_paths   s
    z2TestCommonIOCapabilities.test_get_handle_with_pathc              	   C   sx   t ƒ �T}t |d¡�}|j|ks$J ‚W d   ƒ n1 s80    Y  |jrLJ ‚W d   ƒ n1 s`0    Y  |jstJ ‚d S )NÚr)r   r   rF   rG   Úclosed)r   Zinput_bufferrJ   r   r   r   Útest_get_handle_with_buffer|   s
    ,(z4TestCommonIOCapabilities.test_get_handle_with_bufferc                 C   s¨   d}t jt|ƒddd��|}d}d}|j |¡}t|ƒ|ks>J ‚t|ƒ|k rjt|j ¡ ƒdks`J ‚||7 }qt||7 }q"|| d¡ks†J ‚W d   ƒ n1 sš0    Y  d S )	Nõ&   a,b,c
1,2,3
Â©,Â®,Â®
Look,a snake,ðŸ��ÚrbF©Úis_textó    é   r   úutf-8)r   rF   r   rG   ÚreadÚlenÚencode)r   ÚdatarJ   r/   Ú	chunksizeÚchunkr   r   r   Ú)test_bytesiowrapper_returns_correct_bytes„   s    
zBTestCommonIOCapabilities.test_bytesiowrapper_returns_correct_bytesc                 C   sŽ   t  d¡}d}t g d¢g d¢g d¢dœ¡}t|ƒ}tj|ddd	��6}| |j¡ 	¡ }t
 ||¡ |jrlJ ‚W d   ƒ n1 s€0    Y  d S )
Nzpyarrow.csvrO   )Ú1õ   Â©ZLook)Ú2õ   Â®za snake)Ú3r`   u   ðŸ��©ÚaÚbÚcrP   FrQ   )r5   r6   ÚpdÚ	DataFramer   r   rF   Úread_csvrG   Z	to_pandasr7   Úassert_frame_equalrM   )r   Zpa_csvrY   r>   ÚsrJ   Údfr   r   r   Útest_get_handle_pyarrow_compat›   s    
ÿz7TestCommonIOCapabilities.test_get_handle_pyarrow_compatc                 C   sÎ   t jt| jƒdd��}t j|dd�}W d   ƒ n1 s80    Y  t  t| jƒ¡}t ||¡ t jt| jƒdd��H}t|ƒ}t ||jdg ¡ t t  |¡|jdd … ¡ W d   ƒ n1 sÀ0    Y  d S )Né   )rZ   T)Zignore_indexr   )	rf   rh   r   Údata1Úconcatr7   ri   ÚnextZiloc)r   Úreaderr/   r>   ÚitÚfirstr   r   r   Útest_iterator¬   s    ,z&TestCommonIOCapabilities.test_iteratorz#reader, module, error_class, fn_extr   ÚcsvÚtxtZxlrdZxlsxZpyarrowÚfeatherÚtablesZh5ZdtaZsas7bdatÚjsonÚpicklec                 C   sÞ   t  |¡ tj tdd| ¡}d|› d�}d|› d�}d}d}	d	|› d
|› d�}
d|› d�}d|› d�}d|› �}t j|d|› d|› d|› d|	› d|
› d|› d|› d|› d�d�� ||ƒ W d   ƒ n1 sÐ0    Y  d S )NrY   údoes_not_exist.úFile (b')?.+does_not_exist\.ú'? does not existú:\[Errno 2\] No such file or directory: '.+does_not_exist\.ú'zExpected object or valueú7path_or_buf needs to be a string file path or file-likeú#\[Errno 2\] File .+does_not_exist\.ú$ does not exist: '.+does_not_exist\.õ<   \[Errno 2\] æ²¡æœ‰é‚£ä¸ªæ–‡ä»¶æˆ–ç›®å½•: '.+does_not_exist\.ú?\[Errno 2\] File o directory non esistente: '.+does_not_exist\.ú+Failed to open local file.+does_not_exist\.ú(ú|ú)©Úmatch)r5   r6   r   r   r&   ÚHEREÚraises)r   rq   ÚmoduleÚerror_classÚfn_extr   Úmsg1Úmsg2Úmsg3Úmsg4Úmsg5Úmsg6Úmsg7Úmsg8r   r   r   Útest_read_non_existent¸   s&    
ÿÿ
ÿ
4þz/TestCommonIOCapabilities.test_read_non_existentz#method, module, error_class, fn_extÚhtmlZparquetc                 C   sz   t  |¡ t g d¢g d¢g d¢dœ¡}tj tddd| ¡}t j|dd	�� |||ƒ W d   ƒ n1 sl0    Y  d S )
N)rm   é   é   )rš   r›   é   )r›   rœ   rT   rb   rY   Zmissing_folderr{   z@Cannot save file into a non-existent directory: .*missing_folderr‰   )	r5   r6   rf   rg   r   r   r&   r‹   rŒ   )r   Úmethodr�   rŽ   r�   Zdummy_framer   r   r   r   Ú#test_write_missing_parent_directoryÞ   s    
þz<TestCommonIOCapabilities.test_write_missing_parent_directoryc                 C   sî   t  |¡ tj dd| ¡}| tddd„ ¡ d|› d�}d|› d	�}d
}	d}
d|› d|› d	�}d|› d	�}d|› d	�}d|› �}t j|d|› d|› d|	› d|
› d|› d|› d|› d|› d�d�� ||ƒ W d   ƒ n1 sà0    Y  d S )Nú~r{   r   c                 S   s   t j d| ¡S )Nr#   )r   r   r&   )Úxr   r   r   Ú<lambda>  rS   zJTestCommonIOCapabilities.test_read_expands_user_home_dir.<locals>.<lambda>r|   r}   r~   r   z0Unexpected character found when decoding 'false'r€   r�   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   )r5   r6   r   r   r&   Úsetattrr   rŒ   )r   rq   r�   rŽ   r�   Zmonkeypatchr   r�   r‘   r’   r“   r”   r•   r–   r—   r   r   r   Útest_read_expands_user_home_dirù   s(    
ÿÿ
ÿ
4þz8TestCommonIOCapabilities.test_read_expands_user_home_dirzreader, module, path)ÚiorY   ru   ziris.csv)r¤   rY   Zfixed_widthzfixed_width_format.txt)r¤   rY   Úexcelz
test1.xlsx)r¤   rY   rw   zfeather-0_3_1.feather)r¤   rY   Z
legacy_hdfzdatetimetz_object.h5)r¤   rY   Ústatazstata10_115.dta)r¤   ÚsasrY   ztest1.sas7bdat)r¤   ry   rY   ztsframe_v012.json)r¤   rY   rz   zcategorical.0.25.0.picklec                 C   sR   t  |¡ ||Ž }t|ƒ}||ƒ}||ƒ}| d¡rBt ||¡ nt ||¡ d S )Nz.pickle)r5   r6   r   Úendswithr7   Zassert_categorical_equalri   )r   rq   r�   r   ÚdatapathÚmypathr/   r>   r   r   r   Útest_read_fspath_all$  s     

z-TestCommonIOCapabilities.test_read_fspath_allz"writer_name, writer_kwargs, moduleÚto_csvÚto_excelÚengineZopenpyxlÚ
to_featherÚto_htmlÚto_jsonÚto_latexÚ	to_pickleÚto_stataZ
time_stampz2019-01-01 00:00c                 C   st  |dv rt  d¡ t d¡}t d¡}t dddgi¡}|�� }|�ú}t  |¡ t|ƒ}	t||ƒ}
|
|fi |¤Ž |
|	fi |¤Ž t|dƒ�’}t|dƒ�f}|d	krÔtj	|fi |¤Ž}tj	|fi |¤Ž}t 
||¡ n| ¡ }| ¡ }||ksðJ ‚W d   ƒ n1 �s0    Y  W d   ƒ n1 �s&0    Y  W d   ƒ n1 �sF0    Y  W d   ƒ n1 �sf0    Y  d S )
N)r²   Zjinja2ÚstringÚfspathÚArm   rš   rP   r­   )r5   r6   r7   r8   rf   rg   r   Úgetattrr9   Ú
read_excelri   rV   )r   Zwriter_nameZwriter_kwargsr�   Úp1Úp2rk   rµ   r¶   rª   ÚwriterZf_strZf_pathr/   r>   r   r   r   Útest_write_fspath_allQ  s&    




z.TestCommonIOCapabilities.test_write_fspath_allc           	   	   C   sÈ   t  d¡ t dddgi¡}t d¡}t d¡}|�t}|�P}t|ƒ}|j|dd� |j|dd� tj|dd�}tj|dd�}W d   ƒ n1 s�0    Y  W d   ƒ n1 s®0    Y  t 	||¡ d S )	Nrx   r·   rm   rš   rµ   r¶   r$   )Úkey)
r5   r6   rf   rg   r7   r8   r   Zto_hdfÚread_hdfri   )	r   rk   rº   r»   rµ   r¶   rª   r/   r>   r   r   r   Útest_write_fspath_hdf5x  s    


Jz/TestCommonIOCapabilities.test_write_fspath_hdf5N)6r   r   r   rn   r    r!   r(   ÚtdZ
skip_if_nor,   r0   r:   r5   ÚmarkÚparametrizeÚ
path_typesr?   Ústrr   r   rK   rN   r\   rl   rt   rf   rh   ÚFileNotFoundErrorÚread_fwfr¹   Úread_featherÚOSErrorr¿   Ú
read_stataÚread_sasÚ	read_jsonÚread_pickler˜   rg   r¬   r°   r­   r¯   Z
to_parquetr´   r±   r³   rž   Z
read_tabler£   r«   Úto_datetimer½   rÀ   r   r   r   r   r   :   sÆ   	


÷þ
øþ
öþ


ý
ýý


ýêþ
øþ
r   c                 C   s   | ddddƒS )Nr¤   rY   ru   ztest_mmap.csvr   )r©   r   r   r   Ú	mmap_file�  s    rÏ   c                   @   sX   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zej 	d	d
dg¡ej 	dddg¡dd„ ƒƒZ
dS )ÚTestMMapWrapperc                 C   sÔ   t dƒ}dd„ |_tƒ r"d}t}n
d}tj}tj||d�� t 	|d¡ W d   ƒ n1 s\0    Y  t
|dd	��}W d   ƒ n1 sˆ0    Y  d
}tjt|d�� t 	|d¡ W d   ƒ n1 sÆ0    Y  d S )NzI am not a filec                   S   s   dS )Néÿÿÿÿr   r   r   r   r   r¡   •  rS   z;TestMMapWrapper.test_constructor_bad_file.<locals>.<lambda>zThe parameter is incorrectz
[Errno 22]r‰   TrU   ©ÚencodingzI/O operation on closed file)r   Úfilenor   rÉ   ÚmmapÚerrorr5   rŒ   r   Z_maybe_memory_mapr9   Ú
ValueError)r   rÏ   Znon_fileÚmsgÚerrÚtargetr   r   r   Útest_constructor_bad_file“  s    
*z)TestMMapWrapper.test_constructor_bad_filec              
   C   sà   t |dd��À}| ¡ }tj|dddd��†}|j}t|jjtjƒsDJ ‚|D ] }t|ƒ}| 	¡ | 	¡ ksHJ ‚qHt
jtdd�� t|ƒ W d   ƒ n1 s–0    Y  W d   ƒ n1 s´0    Y  W d   ƒ n1 sÒ0    Y  d S )NrU   rÒ   rL   T)rR   Ú
memory_mapz^$r‰   )r9   Ú	readlinesr   rF   rG   Ú
isinstanceÚbufferrÕ   rp   Ústripr5   rŒ   ÚStopIteration)r   rÏ   rÚ   ÚlinesZwrappersÚwrapperÚlineÚ	next_liner   r   r   Ú	test_next©  s    ÿzTestMMapWrapper.test_nextc              	   C   s¸   t  ¡ �œ}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d
d�� tj|dd� W d   ƒ n1 sŒ0    Y  W d   ƒ n1 sª0    Y  d S )Nçš™™™™™ñ?éx   ©é   rœ   ÚABCD©Zdtypec                 S   s   g | ]}d |› �‘qS ©zi-r   ©Ú.0Úir   r   r   Ú
<listcomp>¿  rS   z7TestMMapWrapper.test_unknown_engine.<locals>.<listcomp>rê   ©ÚcolumnsÚindexzUnknown enginer‰   Zpyt)r®   )r7   r8   rf   rg   ÚnpÚarangeÚreshapeÚIndexÚlistÚobjectÚranger¬   r5   rŒ   r×   rh   ©r   r   rk   r   r   r   Útest_unknown_engineº  s    
ý
z#TestMMapWrapper.test_unknown_enginec                 C   s–   t  ¡ �z}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� t  |tj|dd�¡ W d  ƒ n1 sˆ0    Y  dS )z\
        'encoding' shouldn't be passed to 'open' in binary mode.

        GH 35058
        rç   rè   ré   rë   rì   c                 S   s   g | ]}d |› �‘qS rí   r   rî   r   r   r   rñ   Ï  rS   z4TestMMapWrapper.test_binary_mode.<locals>.<listcomp>rê   rò   zw+br3   r   ©Z	index_colN)r7   r8   rf   rg   rõ   rö   r÷   rø   rù   rú   rû   r¬   ri   rh   rü   r   r   r   Útest_binary_modeÅ  s    
ýz TestMMapWrapper.test_binary_moderÓ   zutf-16zutf-32Úcompression_Úbz2Úxzc              	   C   sî   t jdt d¡ d¡ t jtdƒtd�t jdd„ tdƒD ƒtd�d	�}t	 
¡ �Œ}t	 t¡�  |j|||d
� W d  ƒ n1 s€0    Y  d}tjt|d��  t j|||d
� W d  ƒ n1 sÂ0    Y  W d  ƒ n1 sà0    Y  dS )zš
        bz2 and xz do not write the byte order mark (BOM) for utf-16/32.

        https://stackoverflow.com/questions/55171439

        GH 35681
        rç   rè   ré   rë   rì   c                 S   s   g | ]}d |› �‘qS rí   r   rî   r   r   r   rñ   á  rS   z@TestMMapWrapper.test_warning_missing_utf_bom.<locals>.<listcomp>rê   rò   )r<   rÓ   NzHUTF-\d+ stream does not start with BOM|'utf-\d+' codec can't decode byter‰   )rf   rg   rõ   rö   r÷   rø   rù   rú   rû   r7   r8   Zassert_produces_warningÚUnicodeWarningr¬   r5   rŒ   ÚUnicodeErrorrh   )r   rÓ   r   rk   r   rØ   r   r   r   Útest_warning_missing_utf_bomÔ  s    
ý
.ÿz,TestMMapWrapper.test_warning_missing_utf_bomN)r   r   r   rÛ   ræ   rý   rÿ   r5   rÂ   rÃ   r  r   r   r   r   rÐ   ’  s   rÐ   c                   C   s‚   t  d¡sJ ‚t  d¡sJ ‚t  d¡r*J ‚t  d¡r8J ‚t  d¡rFJ ‚t  d¡rTJ ‚t  d¡rbJ ‚t  d¡rpJ ‚t  d	¡s~J ‚d S )
Nzgcs://pandas/somethingelse.comzgs://pandas/somethingelse.comzhttp://pandas/somethingelse.comzrandom:pandas/somethingelse.comz/local/pathzrelative/local/pathzthis is not fsspec://urlz({'url': 'gs://pandas/somethingelse.com'}z#RFC-3986+compliant.spec://something)r   Zis_fsspec_urlr   r   r   r   Útest_is_fsspec_urlð  s    r  rÓ   rU   Úformatru   ry   c              	   C   s  t jdt d¡ d¡ t jtdƒtd�t jdd„ tdƒD ƒtd�d	�}t	 
¡ �¦}tj|d
| d��$}t|d|› �ƒ|ƒ W d   ƒ n1 sŠ0    Y  tj|d| d��2}|dkr¾t j|dd�}n
t  |¡}W d   ƒ n1 sÜ0    Y  W d   ƒ n1 sú0    Y  t	 ||¡ d S )Nrç   rè   ré   rë   rì   c                 S   s   g | ]}d |› �‘qS rí   r   rî   r   r   r   rñ     rS   z(test_codecs_encoding.<locals>.<listcomp>rê   rò   rA   )r4   rÓ   Zto_rL   ru   r   rþ   )rf   rg   rõ   rö   r÷   rø   rù   rú   rû   r7   r8   Úcodecsr9   r¸   rh   rÌ   ri   )rÓ   r  r>   r   rG   rk   r   r   r   Útest_codecs_encodingÿ  s    ý
2Fr	  c               
   C   sJ  t jdt d¡ d¡ t jtdƒtd�t jdd„ tdƒD ƒtd�d	�} t	 
¡ �Ú}t|d
ƒ�H}t d¡|ƒ�}|  |¡ W d   ƒ n1 sŠ0    Y  W d   ƒ n1 s¨0    Y  t|dƒ�L}t d¡|ƒ�}t j|dd�}W d   ƒ n1 sð0    Y  W d   ƒ n1 �s0    Y  W d   ƒ n1 �s00    Y  t	 | |¡ d S )Nrç   rè   ré   rë   rì   c                 S   s   g | ]}d |› �‘qS rí   r   rî   r   r   r   rñ     rS   z1test_codecs_get_writer_reader.<locals>.<listcomp>rê   rò   r2   rU   rP   r   rþ   )rf   rg   rõ   rö   r÷   rø   rù   rú   rû   r7   r8   r9   r  Ú	getwriterr¬   Ú	getreaderrh   ri   )r>   r   rG   Úencodedrk   r   r   r   Útest_codecs_get_writer_reader  s    ý
Flr  zio_class,mode,msgÚtz*a bytes-like object is required, not 'str'rd   z%string argument expected, got 'bytes'c              	   C   s²   t jdt d¡ d¡ t jtdƒtd�t jdd„ tdƒD ƒtd�d	�}| ƒ �R}t	j
t|d
��$ |j|d|› �d� W d   ƒ n1 s†0    Y  W d   ƒ n1 s¤0    Y  d S )Nrç   rè   ré   rë   rì   c                 S   s   g | ]}d |› �‘qS rí   r   rî   r   r   r   rñ   2  rS   z*test_explicit_encoding.<locals>.<listcomp>rê   rò   r‰   rA   r3   )rf   rg   rõ   rö   r÷   rø   rù   rú   rû   r5   rŒ   Ú	TypeErrorr¬   )Zio_classr4   rØ   r>   rß   r   r   r   Útest_explicit_encoding$  s    ýr  Úencoding_errors)NÚstrictÚreplacec              	   C   s,  d}d}|dkr<d| d |d  d | }t tjdd�}n.d	|d  d
 | d | d }t tjdd�}t ¡ �¤}t|ƒ}| |¡ | dkrÊtj	t
|d�� ||| d� W d   ƒ n1 s¾0    Y  n>||| d�}|j| d�}	tj|	|	gi|	d gd�}
t ||
¡ W d   ƒ n1 �s0    Y  d S )Nz'utf-8' codec can't decode byteó   äru   ó   ,ó   
rš   r   rþ   s   {"s   ": {"s   ":"s   "}}rô   )Zorientr  r‰   )r  ©Úerrors)rô   )r   rf   rh   rÌ   r7   r8   r   Úwrite_bytesr5   rŒ   ÚUnicodeDecodeErrorÚdecoderg   ri   )r  r  rØ   Zbad_encodingÚcontentrq   r   Úfilerk   Údecodedr>   r   r   r   Útest_encoding_errors9  s<    ÿþýüûúÿ	

,r  c               	   C   sj   t  ¡ �N} tjtdd��  tj| ddd� W d   ƒ n1 s>0    Y  W d   ƒ n1 s\0    Y  d S )Nzunknown error handler namer‰   rA   Úbadr  )r7   r8   r5   rŒ   ÚLookupErrorr   rF   r   r   r   r   Útest_bad_encdoing_errors\  s    
r"  c                  C   sL   t jtdd��*} t d¡ | jtjks*J ‚W d   ƒ n1 s>0    Y  d S )Nz\[Errno 2\]r‰   Zdoesnt_exist)r5   rŒ   rÆ   rf   rh   ÚerrnoÚENOENT)rÙ   r   r   r   Útest_errno_attributec  s    
r%  c               	   C   sh   t jtdd��F tƒ � } tj| ddd� W d   ƒ n1 s<0    Y  W d   ƒ n1 sZ0    Y  d S )NrÔ   r‰   rP   T)rÜ   )r5   rŒ   r   r   r   rF   )rß   r   r   r   Útest_fail_mmapj  s    r&  c               
   C   s    G dd„ dƒ} t jtdd��p tƒ �J}t |d¡�}|j | ƒ ¡ W d   ƒ n1 sV0    Y  W d   ƒ n1 st0    Y  W d   ƒ n1 s’0    Y  d S )Nc                   @   s   e Zd Zdd„ ZdS )z&test_close_on_error.<locals>.TestErrorc                 S   s   t dƒ‚d S )NÚtest)rÉ   r   r   r   r   Úcloses  s    z,test_close_on_error.<locals>.TestError.closeN)r   r   r   r(  r   r   r   r   Ú	TestErrorr  s   r)  r'  r‰   rP   )r5   rŒ   rÉ   r   r   rF   Zcreated_handlesÚappend)r)  rß   rJ   r   r   r   Útest_close_on_errorp  s
    r+  rq   c                 C   s6   t ƒ �}t | |¡ W d   ƒ n1 s(0    Y  d S r
   )r   rz   Údump)rq   rß   r   r   r   Útest_pickle_reader|  s    r-  )Hr   r  r#  Ú	functoolsr   r¤   r   r   r   rÕ   r   Úpathlibr   rz   rB   Únumpyrõ   r5   Zpandas.compatr   Zpandas.util._test_decoratorsÚutilZ_test_decoratorsrÁ   Zpandasrf   Zpandas._testingZ_testingr7   Zpandas.io.commonÚcommonr   rÂ   ÚfilterwarningsZ
pytestmarkr   rÅ   rÄ   Zpy.pathr   r*   r*  ÚImportErrorr   r)   ÚdirnameÚ__file__r‹   r   ZfixturerÏ   rÐ   r  rÃ   r	  r  r  r  r"  r%  r&  r+  rh   rÇ   r¹   rÈ   r¿   rÊ   rË   rÌ   rÍ   r-  r   r   r   r   Ú<module>   s„   ÿ
  U
^þþ
!÷þ