o
    ŀg2                     @   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 ddl	m
Z ddlmZ ddlm  m  mZ ejdZejdd	gd
d ddd ZG dd dZ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)ParserError)read_csvz=ignore:Passing a BlockManager to DataFrame:DeprecationWarningpythonz
python-fwfc                 C      | S N )valr	   r	   [/var/www/html/myenv/lib/python3.10/site-packages/pandas/tests/io/parser/test_unsupported.py<lambda>       r   )paramsidsc                 C      | 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   sR   d}dD ]"}t jtdd tt||dd W d    n1 s!w   Y  qd S )Na b c
1 2 3)cr   zunexpected keywordmatchT)enginemangle_dupe_cols)pytestraises	TypeErrorr   r   )selfdatar   r	   r	   r   test_mangle_dupe_cols_false!   s   z3TestUnsupportedFeatures.test_mangle_dupe_cols_falsec              	   C   s  d}d}d}t jt|d) tjt|d tt|dd dd W d    n1 s*w   Y  W d    n1 s9w   Y  t jt|d tt|ddd	 W d    n1 sYw   Y  t jt|d tt|dd
tdd W d    n1 s|w   Y  t jt|d tt|ddd W d    n1 sw   Y  tt	j
tf tt|d dd W d    n1 sw   Y  tt	j
 tt|dd W d    n1 sw   Y  tt	j
 tt|d
tdd W d    n1 sw   Y  tt	j
 tt|dd W d    n	1 sw   Y  d}d}t jt|d tt|dd W d    n	1 s?w   Y  t jt|d tt|ddd	 W d    n	1 s`w   Y  d}d}t jt|d tt|dd W d    n	1 sw   Y  t jt|d tt|dd W d    n	1 sw   Y  d}d}t jt|d tt|dd W d    d S 1 sw   Y  d S )Nr   zdoes not support;The 'delim_whitespace' keyword in pd.read_csv is deprecatedr   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,,)	thousands z(Only length-1 line terminators supportedza,b,c~~1,2,3~~4,5,6z~~)lineterminator)r   r   
ValueErrortmassert_produces_warningFutureWarningr   r   chrparsersParserWarningr   )r   r   msgdepr_msgtextr	   r	   r   test_c_engine)   sf   $z%TestUnsupportedFeatures.test_c_enginec              	   C   s   ddl m} d}|D ]7}dt| dt| d}|t i}tjt|d tt|fd|i| W d    n1 s<w   Y  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.readersr7   reprobjectr   r   r,   r   r   )r   r   py_unsupportedr   defaultr3   kwargsr	   r	   r   test_python_engine`   s   
z*TestUnsupportedFeatures.test_python_enginec                 C   sZ   G dd d}d}d}t jt|d t|||d W d    d S 1 s&w   Y  d S )Nc                   @   s.   e Zd ZdddZdd Zdd Zd	d
 ZdS )zMTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBufferreturnNc                 S   s
   || _ d S r   r   )r   csv_datar	   r	   r   __init__v      
zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.__init__c                 S   s
   | j  S r   )r   __next__r   r	   r	   r   rE   y   rD   zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.__next__c                 S   r   r   rA   rF   r	   r	   r   read|      zRTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.readc                 S   r   r   rA   rF   r	   r	   r   readline   rH   zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.readline)r@   N)__name__
__module____qualname__rC   rE   rG   rI   r	   r	   r	   r   NoNextBufferu   s
    
rM   za
1zD'NoNextBuffer' object is not iterable|argument 1 must be an iteratorr   )r   )r   r   r   r   )r   r   rM   r   r3   r	   r	   r   test_python_engine_file_no_iters   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r&d	||< n||v r/d
||< n|dkr7d||< d }d }d|v rCd}t}d|v rKd}t}tjt|d+ tj	||d t
t|fddi| W d    n1 sqw   Y  W d    n1 sw   Y  q
d S )Nr   )_pyarrow_unsupportedzJ1,2,3,,
        1,2,3,4,
        1,2,3,4,5
        1,2,,,
        1,2,3,4,r8   z2 option is not supported with the 'pyarrow' enginewarn_bad_lineserror_bad_linesdialectexcelTon_bad_lineswarnr#   r!   verbosez2The 'verbose' keyword in pd.read_csv is deprecatedr   r   pyarrow)r9   rO   r:   r;   r/   r   r   r,   r-   r.   r   r   )	r   pa_unsupportedr   r=   r3   r>   default_needs_boolrU   r4   r	   r	   r   test_pyarrow_engine   s:   


z+TestUnsupportedFeatures.test_pyarrow_enginec                 C   sv   t d}dd }|}|jdvr2d}tjt|d |j||d W d    d S 1 s+w   Y  d S |j||d d S )Nza,b
1,2c                 S   r   r   r	   )xr	   r	   r   r      r   zVTestUnsupportedFeatures.test_on_bad_lines_callable_python_or_pyarrow.<locals>.<lambda>)r   rW   zKon_bad_line can only be a callable function if engine='python' or 'pyarrow'r   )rT   )r   r   r   r   r,   r   )r   all_parserssiobad_lines_funcparserr3   r	   r	   r   ,test_on_bad_lines_callable_python_or_pyarrow   s   
"zDTestUnsupportedFeatures.test_on_bad_lines_callable_python_or_pyarrowN)	rJ   rK   rL   r    r6   r?   rN   rZ   r`   r	   r	   r	   r   r       s    7$r   c              
   C   s   | }t }|jdkrtjdd tdL}t|jddd td( tj	|d	d
 |j
|g dd W d    n1 s?w   Y  W d    n1 sNw   Y  t| W d    d S 1 scw   Y  d S )NrW   z,https://github.com/apache/arrow/issues/38676reasonztest.csvzcol1,col2
a,b
1,2zutf-8)encodingFcol3r   )col1col2rd   )usecols)r,   r   r   skipr-   ensure_cleanr   
write_textr.   r   r   osunlink)r\   r_   errorfnamer	   r	   r   )test_close_file_handle_on_invalid_usecols   s   
"ro   c                 C   sh   |}|j dkr| tjj|j  dd tjtdd |g  W d    d S 1 s-w   Y  d S )Nr   z engine supports lists.ra   Invalidr   )r   applymarkerr   markxfailr   r,   r   )r   r\   r_   r	   r	   r   test_invalid_file_inputs   s   
"rt   c                 C   sJ   | }d}t jt|d |jddd W d    d S 1 sw   Y  d S )NzPdtype_backend numpy is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.r   testnumpy)dtype_backend)r   r   r,   r   )r\   r_   r3   r	   r	   r   test_invalid_dtype_backend   s   "rx   )__doc__ior   rk   pathlibr   r   pandas.errorsr   pandas._testing_testingr-   pandas.io.parsersr   r9   r1   readersrr   filterwarnings
pytestmarkfixturer   r   ro   rt   rx   r	   r	   r	   r   <module>   s&    
 