U
    +if                     @   s   d Z ddlmZ ddlZddlmZ ddlZddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlm  m  mZ ejdd	gd
d ddd ZG dd dZdd Zdd ZdS )a  
Tests that features that are currently unsupported in
either the Python or C parser are actually enforced
and are clearly communicated to the user.

Ultimately, the goal is to remove test cases from this
test suite as new feature support is added to the parsers.
    )StringION)Path)is_ci_environmentis_platform_macis_platform_windows)ParserError)read_csvpythonz
python-fwfc                 C   s   | S N )valr   r   Z/home/mars/bis/venv/lib/python3.8/site-packages/pandas/tests/io/parser/test_unsupported.py<lambda>       r   )paramsZidsc                 C   s   | j S r
   )param)requestr   r   r   python_engine   s    r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestUnsupportedFeaturesc              
   C   sB   d}d}dD ]0}t jt|d tt||dd W 5 Q R X qd S )Na b c
1 2 3zis not supported)cr	   matchF)engineZmangle_dupe_cols)pytestraises
ValueErrorr   r   )selfdatamsgr   r   r   r   test_mangle_dupe_cols_false"   s
    z3TestUnsupportedFeatures.test_mangle_dupe_cols_falsec              	   C   sX  d}d}t jt|d tt|dd dd W 5 Q R X t jt|d tt|ddd W 5 Q R X t jt|d tt|dd	td
d W 5 Q R X t jt|d tt|ddd W 5 Q R X ttj	 tt|d dd W 5 Q R X ttj	 tt|dd W 5 Q R X ttj	 tt|d	td
d W 5 Q R X ttj	 tt|dd W 5 Q R X d}d}t jt
|d tt|dd W 5 Q R X t jt
|d tt|ddd W 5 Q R X d}d}t jt|d tt|dd W 5 Q R X t jt|d tt|dd W 5 Q R X d}d}t jt|d tt|dd W 5 Q R X d S )Nr   zdoes not supportr   r   F)r   sepdelim_whitespacez\s)r   r!   	   )r   r!   	quotechar   )r   
skipfooter)r!   r"   )r!   )r!   r%   )r'   a                        A       B       C       D        E
one two three   four
a   b   10.0032 5    -0.5109 -2.3358 -0.4645  0.05076  0.3640
a   q   20      4     0.4473  1.4152  0.2834  1.00661  0.1744
x   q   30      3    -0.6662 -0.5243 -0.3580  0.89145  2.5838zError tokenizing dataz\s+z)Only length-1 thousands markers supportedzA|B|C
1|2,334|5
10|13|10.
z,,)Z	thousands z(Only length-1 line terminators supportedza,b,c~~1,2,3~~4,5,6z~~)lineterminator)r   r   r   r   r   chrtmassert_produces_warningparsersZParserWarningr   )r   r   r   textr   r   r   test_c_engine+   sD    " z%TestUnsupportedFeatures.test_c_enginec              
   C   st   ddl m} d}|D ]Z}dt| dt| d}|t i}tjt|d tt|fd|i| W 5 Q R X qd S )	Nr   )_python_unsupportedz*1,2,3,,
1,2,3,4,
1,2,3,4,5
1,2,,,
1,2,3,4,The z" option is not supported with the z enginer   r   )	pandas.io.parsers.readersr0   reprobjectr   r   r   r   r   )r   r   Zpy_unsupportedr   defaultr   kwargsr   r   r   test_python_engine_   s    
z*TestUnsupportedFeatures.test_python_enginec              	   C   sD   G dd d}d}d}t jt|d t|||d W 5 Q R X d S )Nc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
zMTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBufferc                 S   s
   || _ d S r
   r   )r   Zcsv_datar   r   r   __init__u   s    zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.__init__c                 S   s
   | j  S r
   )r   __next__r   r   r   r   r:   x   s    zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.__next__c                 S   s   | j S r
   r8   r;   r   r   r   read{   s    zRTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.readc                 S   s   | j S r
   r8   r;   r   r   r   readline~   s    zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.readlineN)__name__
__module____qualname__r9   r:   r<   r=   r   r   r   r   NoNextBuffert   s   rA   za
1zD'NoNextBuffer' object is not iterable|argument 1 must be an iteratorr   )r   )r   r   	TypeErrorr   )r   r   rA   r   r   r   r   r   test_python_engine_file_no_iterr   s
    z7TestUnsupportedFeatures.test_python_engine_file_no_iterc              
   C   s   ddl m} d}|D ]}dt| d}|t i}ddh}|dkrLd	||< n"||kr^d
||< n|dkrnd||< tjt|d tt|fddi| W 5 Q R X qd S )Nr   )_pyarrow_unsupportedzJ1,2,3,,
        1,2,3,4,
        1,2,3,4,5
        1,2,,,
        1,2,3,4,r1   z2 option is not supported with the 'pyarrow' engineZwarn_bad_linesZerror_bad_linesdialectexcelTon_bad_lineswarnr   r   pyarrow)	r2   rD   r3   r4   r   r   r   r   r   )r   Zpa_unsupportedr   r5   r   r6   Zdefault_needs_boolr   r   r   test_pyarrow_engine   s    


z+TestUnsupportedFeatures.test_pyarrow_enginec              	   C   s^   t d}dd }|}|jdkrLd}tjt|d |j||d W 5 Q R X n|j||d d S )Nza,b
1,2c                 S   s   | S r
   r   )xr   r   r   r      r   zPTestUnsupportedFeatures.test_on_bad_lines_callable_python_only.<locals>.<lambda>r	   z>on_bad_line can only be a callable function if engine='python'r   )rG   )r   r   r   r   r   r   )r   all_parserssioZbad_lines_funcparserr   r   r   r   &test_on_bad_lines_callable_python_only   s    
z>TestUnsupportedFeatures.test_on_bad_lines_callable_python_onlyN)	r>   r?   r@   r    r/   r7   rC   rJ   rO   r   r   r   r   r   !   s   	4r   c                 C   s   | }t }|jdkr@td}|jj}t r@t s6t r@t	d t
db}t|d t
d4 tj|dd |j|dd	dgd
 W 5 Q R X W 5 Q R X t| W 5 Q R X d S )NrI   z:GH#45547 causing timeouts on windows/mac builds 2022-01-22ztest.csvzcol1,col2
a,b
1,2FZcol3r   Zcol1Zcol2)Zusecols)r   r   r   ZimportorskiplibZArrowKeyErrorr   r   r   skipr+   Zensure_cleanr   
write_textr,   r   r   osunlink)rL   rN   errorrI   fnamer   r   r   *test_close_file_handle_on_invalide_usecols   s    


(rW   c              	   C   s@   | }|j dkrtd tjtdd |g  W 5 Q R X d S )Nr	   zPython engine supports lists.ZInvalidr   )r   r   rQ   r   r   r   )rL   rN   r   r   r   test_invalid_file_inputs   s
    

rX   )__doc__ior   rS   pathlibr   r   Zpandas.compatr   r   r   Zpandas.errorsr   Zpandas._testingZ_testingr+   Zpandas.io.parsersr   r2   r-   ZreadersZfixturer   r   rW   rX   r   r   r   r   <module>   s   
 