HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/tests/io/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/tests/io/__pycache__/test_common.cpython-36.pyc
3

���h�4�@sdZddlmZddlZddlZddlmZddlZddlm	Z	ddl
jjZ
ddlZddljZddljjZGdd�d�ZeeegZyddlmZeje�Wnek
r�YnXejjejj e!��Z"ej#j$d	�Gd
d�d��Z%ej&dd
��Z'Gdd�d�Z(dd�Z)dS)z0
Tests for the pandas.io.common functionalities
�)�StringION)�Path)�is_platform_windowsc@s eZdZdZdd�Zdd�ZdS)�CustomFSPathz%For testing fspath on unknown objectscCs
||_dS)N)�path)�selfr�r�=/tmp/pip-build-5_djhm0z/pandas/pandas/tests/io/test_common.py�__init__szCustomFSPath.__init__cCs|jS)N)r)rrrr	�
__fspath__szCustomFSPath.__fspath__N)�__name__�
__module__�__qualname__�__doc__r
rrrrr	rsr)�localz*ignore:can't resolve package:ImportWarningc@s�eZdZdZdd�Zdd�Zdd�Zejd�d	d
��Z	dd�Z
ejj
d
d\d]d^d_d`dadbdcddg	�ejj
de�dd���Zdd �Zd!d"�Zd#d$�Zejj
d%ejd&ed'fejd&ed(fejd)ed*fejd+ed,fejd-ed.fejd&ed/fejd&ed0fejd&ed1fejd&ed2fg	�d3d4��Z ejj
d%ejd&ed'fej!d&ed'fejd&ed(fejd)ed*fejd+ed,fejd-ed.fejd&ed/fejd&ed0fejd&ed1fejd&ed2fg
�d5d6��Z"ejj
d7ejd&defej!d&dffejd&dgfejd)dhfejd+difejd-djfejd&dkfejd&dlfejd&dmfejd&dnfg
�ejj#dH�dIdJ���Z$ejj
dKdLid&fdMdNdOidOfdPid+fdQid&fdRid&fdSid&fdTid&fdUdVej%dW�id&fg�dXdY��Z&dZd[�Z'dS)o�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
cCsBd}tj|�}||kst�tjj|�s*t�tjj|�|ks>t�dS)Nz
~/sometest)�icom�_expand_user�AssertionError�osr�isabs�
expanduser)r�filename�
expanded_namerrr	�test_expand_user7s

z)TestCommonIOCapabilities.test_expand_usercCs2d}tj|�}||kst�tjj|�|ks.t�dS)Nz/somefolder/sometest)rrrrrr)rrrrrr	�test_expand_user_normal_path?s
z5TestCommonIOCapabilities.test_expand_user_normal_pathcCsBtjtd��}|dkst�tjtd��}|tjjdd�ks>t�dS)N�.zfoo//bar�foo�bar)r�stringify_pathrrrr�join)r�rel_pathZredundant_pathrrr	�test_stringify_path_pathlibFsz4TestCommonIOCapabilities.test_stringify_path_pathlibzpy.pathcCs8tjjdd�}tjj|�}t|�}tj|�|ks4t�dS)Nrr)rrr �abspath�	LocalPathrrr)rr�abs_pathZlpathrrr	�test_stringify_path_localpathLsz6TestCommonIOCapabilities.test_stringify_path_localpathcCs"td�}tj|�}|dkst�dS)Nzfoo/bar.csv)rrrr)r�p�resultrrr	�test_stringify_path_fspathSs
z3TestCommonIOCapabilities.test_stringify_path_fspathzextension,expected�N�.gz�gzip�.bz2�bz2�.zip�zip�.xz�xz�.GZ�.BZ2�.ZIP�.XZ�	path_typecCs*|d|�}tj|dd�}||ks&t�dS)Nzfoo/bar.csvZinfer)�compression)rZinfer_compressionr)r�	extension�expectedr7rr8rrr	� test_infer_compression_from_pathXsz9TestCommonIOCapabilities.test_infer_compression_from_pathcCsTd}tj|�\}}}}||ks"t�tjj|�s2t�tjj|�|ksFt�|sPt�dS)Nz
~/sometest)r�get_filepath_or_bufferrrrrr)rr�filepath_or_buffer�_�should_closerrr	�%test_get_filepath_or_buffer_with_pathlsz>TestCommonIOCapabilities.test_get_filepath_or_buffer_with_pathcCs2t�}tj|�\}}}}||ks$t�|s.t�dS)N)rrr<r)rZinput_bufferr=r>r?rrr	�'test_get_filepath_or_buffer_with_bufferts
z@TestCommonIOCapabilities.test_get_filepath_or_buffer_with_buffercCs�tjt|j�dd�}tj|dd�}tjt|j��}tj||�tjt|j�dd�}t|�}tj||jdg�tjtj|�|jdd��dS)N�)�	chunksizeT)Zignore_indexr)	�pd�read_csvr�data1�concat�tm�assert_frame_equal�nextZiloc)r�readerr(r:�it�firstrrr	�
test_iterator|sz&TestCommonIOCapabilities.test_iteratorz#reader, module, error_class, fn_extr�csv�txtZxlrdZxlsxZpyarrow�feather�tables�h5ZdtaZsas7bdat�json�picklecCs�tj|�tjjtdd|�}d|�d�}d|�d�}d}d}	d	|�d
|�d�}
d|�d�}d|�d�}d
|��}
tj|d|�d|�d|�d|	�d|
�d|�d|�d|
�d�d��||�WdQRXdS)N�datazdoes_not_exist.zFile (b')?.+does_not_exist\.z'? does not existz:\[Errno 2\] No such file or directory: '.+does_not_exist\.�'zExpected object or valuez7path_or_buf needs to be a string file path or file-likez#\[Errno 2\] File .+does_not_exist\.z$ does not exist: '.+does_not_exist\.u<\[Errno 2\] 没有那个文件或目录: '.+does_not_exist\.z?\[Errno 2\] File o directory non esistente: '.+does_not_exist\.z+Failed to open local file.+does_not_exist\.�(�|�))�match)�pytest�importorskiprrr �HERE�raises)rrK�module�error_class�fn_extr�msg1�msg2�msg3�msg4�msg5�msg6�msg7�msg8rrr	�test_read_non_existent�s

<z/TestCommonIOCapabilities.test_read_non_existentcCs�tj|�tjjdd|�}|jtddd��d|�d�}d|�d	�}d
}	d}
d|�d
|�d	�}d|�d	�}d|�d	�}
d|��}tj|d|�d|�d|	�d|
�d|�d|�d|
�d|�d�d��||�WdQRXdS)N�~zdoes_not_exist.rcSstjjd|�S)Nr)rrr )�xrrr	�<lambda>�szJTestCommonIOCapabilities.test_read_expands_user_home_dir.<locals>.<lambda>zFile (b')?.+does_not_exist\.z'? does not existz:\[Errno 2\] No such file or directory: '.+does_not_exist\.rWz0Unexpected character found when decoding 'false'z7path_or_buf needs to be a string file path or file-likez#\[Errno 2\] File .+does_not_exist\.z$ does not exist: '.+does_not_exist\.u<\[Errno 2\] 没有那个文件或目录: '.+does_not_exist\.z?\[Errno 2\] File o directory non esistente: '.+does_not_exist\.z+Failed to open local file.+does_not_exist\.rXrYrZ)r[)r\r]rrr �setattrrr_)rrKr`rarbZmonkeypatchrrcrdrerfrgrhrirjrrr	�test_read_expands_user_home_dir�s

<z8TestCommonIOCapabilities.test_read_expands_user_home_dirzreader, module, path�iorV�iris.csv�fixed_width�fixed_width_format.txt�excel�
test1.xlsx�feather-0_3_1.feather�
legacy_hdf�datetimetz_object.h5�stata�stata10_115.dta�sas�test1.sas7bdat�tsframe_v012.json�categorical.0.25.0.picklez�ignore:This method will be removed in future versions.  Use 'tree.iter\(\)' or 'list\(tree.iter\(\)\)' instead.:PendingDeprecationWarningcCsRtj|�||�}t|�}||�}||�}|jd�rBtj||�ntj||�dS)Nz.pickle)r\r]r�endswithrHZassert_categorical_equalrI)rrKr`r�datapath�mypathr(r:rrr	�test_read_fspath_all�s%

z-TestCommonIOCapabilities.test_read_fspath_allz"writer_name, writer_kwargs, module�to_csvZto_excel�engineZxlwtZ
to_featherZto_htmlZto_jsonZto_latexZ	to_pickleZto_stataZ
time_stampz2019-01-01 00:00cCs�tjd�}tjd�}tjdddgi�}|��}|��}tj|�t|�}	t||�}
|
|f|�t|d��}|j	�}WdQRX|
|	f|�t|d��}|j	�}
WdQRX|
|ks�t
�WdQRXWdQRXdS)N�string�fspath�ArB��rb)rH�ensure_cleanrD�	DataFramer\r]r�getattr�open�readr)rZwriter_nameZ
writer_kwargsr`�p1�p2�dfr�r�r��writer�fr:r(rrr	�test_write_fspath_alls



z.TestCommonIOCapabilities.test_write_fspath_allc	Cs�tjd�tjdddgi�}tjd�}tjd�}|�V}|�F}t|�}|j|dd�|j|dd�tj|dd�}tj|dd�}WdQRXWdQRXtj	||�dS)	NrRr�rBr�r�r�r)�key)
r\r]rDr�rHr�rZto_hdf�read_hdfrI)	rr�r�r�r�r�r�r(r:rrr	�test_write_fspath_hdf5,s


"z/TestCommonIOCapabilities.test_write_fspath_hdf5)r*N)r+r,)r-r.)r/r0)r1r2)r3r,)r4r.)r5r0)r6r2)rqrVrOrr)rqrVrOrr)rqrVrsrt)rqrVrurv)rqrVrQrw)rqrVrxry)rqrVrzr{)rqr|rVr})rqrTrVr~)rqrVrUr)(rr
rrFrrr"�tdZ
skip_if_nor&r)r\�markZparametrize�
path_typesr;r@rArNrDrE�FileNotFoundErrorZread_fwfZ
read_excelZread_feather�IOErrorr�Z
read_stataZread_sasZ	read_json�
ValueErrorZread_picklerkZ
read_tablerp�filterwarningsr�Zto_datetimer�r�rrrr	r,s�	





 rcCs|dddd�S)NrqrVrOz
test_mmap.csvr)r�rrr	�	mmap_fileAsr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestMMapWrappercCs�td�}dd�|_t�r"d}t}n
d}tj}tj||d��tj	|�WdQRXt
|d�}|j�d}tjt|d��tj	|�WdQRXdS)	NzI am not a filecSsdS)NrB���rrrrr	rnIsz;TestMMapWrapper.test_constructor_bad_file.<locals>.<lambda>zThe parameter is incorrectz
[Errno 22])r[�rzI/O operation on closed file)
r�filenor�OSError�mmap�errorr\r_r�_MMapWrapperr��closer�)rr�Znon_file�msg�err�targetrrr	�test_constructor_bad_fileGs

z)TestMMapWrapper.test_constructor_bad_filecCsrt|d��}tj|�}WdQRXt|j�}dd�|D�}|jd�x|D]}t||�sHt�qHWt|d�snt�dS)Nr�cSsg|]}|jd�s|�qS)�__)�
startswith)�.0�attrrrr	�
<listcomp>bsz1TestMMapWrapper.test_get_attr.<locals>.<listcomp>�__next__r)r�rr��dirr��append�hasattrr)rr�r��wrapper�attrsr�rrr	�
test_get_attr]s


zTestMMapWrapper.test_get_attrcCsxt|d��}tj|�}|j�}WdQRXx(|D] }t|�}|j�|j�ks.t�q.Wtjt	dd��t|�WdQRXdS)Nr�z^$)r[)
r�rr��	readlinesrJ�striprr\r_�
StopIteration)rr�r�r��lines�lineZ	next_linerrr	�	test_nextjs

zTestMMapWrapper.test_nextcCsRtj��@}tj�}|j|�tjtdd��tj|dd�WdQRXWdQRXdS)NzUnknown engine)r[Zpyt)r�)	rHr�Z
makeDataFramer�r\r_r�rDrE)rrr�rrr	�test_unknown_enginevs


z#TestMMapWrapper.test_unknown_engineN)rr
rr�r�r�r�rrrr	r�Fs
r�cCs`tjd�st�tjd�st�tjd�s,t�tjd�s<t�tjd�sLt�tjd�s\t�dS)Nzgcs://pandas/somethingelse.comzgs://pandas/somethingelse.comzhttp://pandas/somethingelse.comzrandom:pandas/somethingelse.comz/local/pathzrelative/local/path)rZ
is_fsspec_urlrrrrr	�test_is_fsspec_url~sr�)*rrqrr�rZpathlibrr\Z
pandas.compatrZpandas.util._test_decorators�utilZ_test_decoratorsr�ZpandasrDZpandas._testingZ_testingrHZpandas.io.common�commonrr�strr�Zpy.pathrr$r��ImportErrorrr#�dirname�__file__r^r�r�rZfixturer�r�r�rrrr	�<module>s0

8