
    PiI                     
   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c mc mZ ej                            d          Z ej        dd	gd
           d             Z G d d          Zd Zd Z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                     | S N )vals    {/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/tests/io/parser/test_unsupported.py<lambda>r      s         )paramsidsc                     | j         S r	   )param)requests    r   python_enginer      s
    =r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TestUnsupportedFeaturesc                     d}dD ]T}t          j        t          d          5  t          t	          |          |d           d d d            n# 1 swxY w Y   Ud S )Na b c
1 2 3)cr   zunexpected keywordmatchT)enginemangle_dupe_cols)pytestraises	TypeErrorr   r   )selfdatar   s      r   test_mangle_dupe_cols_falsez3TestUnsupportedFeatures.test_mangle_dupe_cols_false"   s    % 	O 	OFy0DEEE O O$NNNNO O O O O O O O O O O O O O O	O 	Os    AA	A	c           	      p   d}d}t          j        t          |          5  t          t	          |          dd           d d d            n# 1 swxY w Y   t          j        t          |          5  t          t	          |          ddt          d          	           d d d            n# 1 swxY w Y   t          j        t          |          5  t          t	          |          dd
           d d d            n# 1 swxY w Y   t          j        t          j	                  5  t          t	          |          d           d d d            n# 1 swxY w Y   t          j        t          j	                  5  t          t	          |          dt          d                     d d d            n# 1 swxY w Y   t          j        t          j	                  5  t          t	          |          d
           d d d            n# 1 swxY w Y   d}d}t          j        t          |          5  t          t	          |          d           d d d            n# 1 swxY w Y   t          j        t          |          5  t          t	          |          dd           d d d            n# 1 swxY w Y   d}d}t          j        t          |          5  t          t	          |          d           d d d            n# 1 swxY w Y   t          j        t          |          5  t          t	          |          d           d d d            n# 1 swxY w Y   d}d}t          j        t          |          5  t          t	          |          d           d d d            d S # 1 swxY w Y   d S )Nr   zdoes not supportr   r   z\s)r   sep	   )r   r%   	quotechar   )r   
skipfooter)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   
ValueErrorr   r   chrtmassert_produces_warningparsersParserWarningr   )r!   r"   msgtexts       r   test_c_enginez%TestUnsupportedFeatures.test_c_engine*   s"     ]:S111 	< 	<Xd^^CU;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<]:S111 	O 	OXd^^CTSXXNNNN	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O]:S111 	? 	?Xd^^CA>>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? '(=>> 	0 	0Xd^^////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0'(=>> 	C 	CXd^^SBBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C'(=>> 	3 	3Xd^^2222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3A
 &];c222 	1 	1Xd^^0000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1];c222 	= 	=Xd^^CV<<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= : ]:S111 	5 	5Xd^^t4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5]:S111 	3 	3Xd^^r2222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 9$]:S111 	: 	:Xd^^D9999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s    AAA2.B,,B03B0 C>>DD'EEE;-F44F8;F8HHH2II!$I! J//J36J3LLL*MMM?N++N/2N/c                     ddl m} d}|D ]j}d|d|d}|t                      i}t          j        t
          |          5  t          t          |          fd|i| d d d            n# 1 swxY w Y   kd 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.readersr8   objectr   r   r.   r   r   )r!   r   py_unsupportedr"   defaultr4   kwargss          r   test_python_enginez*TestUnsupportedFeatures.test_python_engineZ   s   SSSSSS & 	I 	IG?w ? ?&3? ? ? 
 vxx(Fz555 I I$HHHHHHI I I I I I I I I I I I I I I	I 	Is   A**A.	1A.	c                      G d d          }d}d}t          j        t          |          5  t           ||          |           d d d            d S # 1 swxY w Y   d S )Nc                   (    e Zd ZddZd Zd Zd ZdS )MTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBufferreturnNc                     || _         d S r	   r"   )r!   csv_datas     r   __init__zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.__init__p   s    $			r   c                 4    | j                                         S r	   )r"   __next__r!   s    r   rI   zVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.__next__s   s    y))+++r   c                     | j         S r	   rE   rJ   s    r   readzRTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.readv   
    y r   c                     | j         S r	   rE   rJ   s    r   readlinezVTestUnsupportedFeatures.test_python_engine_file_no_iter.<locals>.NoNextBuffer.readliney   rM   r   )rC   N)__name__
__module____qualname__rG   rI   rL   rO   r
   r   r   NoNextBufferrB   o   sU        % % % %, , ,! ! !! ! ! ! !r   rS   za
1zD'NoNextBuffer' object is not iterable|argument 1 must be an iteratorr   )r   )r   r   r    r   )r!   r   rS   r"   r4   s        r   test_python_engine_file_no_iterz7TestUnsupportedFeatures.test_python_engine_file_no_iterm   s    	! 	! 	! 	! 	! 	! 	! 	! T]9C000 	? 	?\\$''>>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   AAAc                 4   ddl m} d}|D ]}d|d}|t                      i}ddh}|dk    rd	||<   n||v rd
||<   n|dk    rd||<   t          j        t
          |          5  t          t          |          fddi| d d d            n# 1 swxY w Y   d S )Nr   )_pyarrow_unsupportedzJ1,2,3,,
        1,2,3,4,
        1,2,3,4,5
        1,2,,,
        1,2,3,4,r9   z2 option is not supported with the 'pyarrow' enginewarn_bad_lineserror_bad_linesdialectexcelTon_bad_lineswarnr   r   pyarrow)r:   rV   r;   r   r   r.   r   r   )r!   pa_unsupportedr"   r=   r4   r>   default_needs_bools          r   test_pyarrow_enginez+TestUnsupportedFeatures.test_pyarrow_engine   sB   TTTTTT & 	E 	EGVVVVCvxx(F"24E!F)##")w..."&wN**"(wz555 E E$DD	DVDDDE E E E E E E E E E E E E E E	E 	Es   #BB	B	c                    t          d          }d }|}|j        dvrOd}t          j        t          |          5  |                    ||           d d d            d S # 1 swxY w Y   d S |                    ||           d S )Nza,b
1,2c                     | S r	   r
   )xs    r   r   zVTestUnsupportedFeatures.test_on_bad_lines_callable_python_or_pyarrow.<locals>.<lambda>   s    1 r   )r   r]   zKon_bad_line can only be a callable function if engine='python' or 'pyarrow'r   )r[   )r   r   r   r   r.   r   )r!   all_parserssiobad_lines_funcparserr4   s         r   ,test_on_bad_lines_callable_python_or_pyarrowzDTestUnsupportedFeatures.test_on_bad_lines_callable_python_or_pyarrow   s     z""$%:::;  z555 B B.AAAB B B B B B B B B B B B B B B B B B OOCnO=====s   A  A$'A$N)	rP   rQ   rR   r#   r6   r?   rT   r`   rh   r
   r   r   r   r   !   sx        O O O.: .: .:`I I I&? ? ?*E E E.> > > > >r   r   c                    | }t           }|j        dk    rt          j        d           |}t	          |                              dd           t          j        d          5  t          j        |d	          5  |	                    |g d
           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        |           d S )Nr]   z,https://github.com/apache/arrow/issues/38676reasonzcol1,col2
a,b
1,2zutf-8)encodingFcol3r   )col1col2rm   )usecols)r.   r   r   skipr   
write_textr0   r1   r   r   osunlink)rd   	temp_filerg   errorfnames        r   )test_close_file_handle_on_invalid_usecolsrx      sy   FE}	!!IJJJJEKK07CCC		#E	*	* E E]5/// 	E 	EOOE+C+C+CODDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	EE E E E E E E E E E E E E E E Ies6   $B8;B!B8!B%	%B8(B%	)B88B<?B<c                 (   |}|j         dk    r;|                     t          j                            |j          d                     t          j        t          d          5  |                    g            d d d            d S # 1 swxY w Y   d S )Nr   z engine supports lists.rj   Invalidr   )r   applymarkerr   markxfailr   r.   r   )r   rd   rg   s      r   test_invalid_file_inputsr~      s    F}  K%N%N%NOO	
 	
 	
 
z	3	3	3                   s   $BBBc                     | }d}t          j        t          |          5  |                    dd           d d d            d S # 1 swxY 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   )rd   rg   r4   s      r   test_invalid_dtype_backendr      s    F	!  
z	-	-	- 7 7g6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s   AA	A	)__doc__ior   rs   pathlibr   r   pandas.errorsr   pandas._testing_testingr0   pandas.io.parsersr   r:   r2   readersr|   filterwarnings
pytestmarkfixturer   r   rx   r~   r   r
   r   r   <module>r      sX          				        % % % % % %       & & & & & & + + + + + + + + + + + +[''C 

 ,/__EEE  FEF> F> F> F> F> F> F> F>R  $	 	 	7 7 7 7 7r   