o
    _~#g$                     @   s<  d Z ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
mZ ddlmZ ejdZejdZeejd	eed
d
gdd Zedd Zedd Zejddd	dgie
g dg dgg ddfdddgde
g dgg ddfddddgde
d d!ggd"d#gdfged$d% Zed&d' Zejd(d)g d*g d+gfd,g d-g d.gfd/g d0g d1gfged2d3 Zeejd4g d5d6d7 Zed8d9 Zeejd:i e
d;dd<gifdd=gd>e
d=dd<gifgd?d@ ZedAdB Z edCdD Z!edEdF Z"edGdH Z#edIdJ Z$dS )Kzj
Tests that skipped rows are properly handled during
parsing for all of the parsers defined in parsers.py
    )datetime)StringION)EmptyDataError)	DataFrameIndexpyarrow_xfailz=ignore:Passing a BlockManager to DataFrame:DeprecationWarningskiprows   c                 C   sz   | }d}|j t||d ddd}ttdddtdddtdddgdd	}ttd
ddg d|d}t	|| d S )Nzr#foo,a,b,c
#foo,a,b,c
#foo,a,b,c
#foo,a,b,c
#foo,a,b,c
#foo,a,b,c
1/1/2000,1.,2.,3.
1/2/2000,4,5,6
1/3/2000,7,8,9
r   Tr   header	index_colparse_dates           name      ?      $@r   r   r   r   r   columnsindex
read_csvr   r   r   r   nparangereshapetmassert_frame_equal)all_parsersr   parsertextresultr   expected r'   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/tests/io/parser/test_skiprows.pytest_skip_rows_bug   s   
"r)   c                 C   sl   | }dd dd tdD  }dd dd dD  }|jt|dd	gd
}|t|}t|| d S )Nza,b,c

c              	   S   0   g | ]}d  t|t|d t|d gqS ,r   r   joinstr.0ir'   r'   r(   
<listcomp>;      0 z'test_deep_skip_rows.<locals>.<listcomp>
   c              	   S   r+   r,   r.   r1   r'   r'   r(   r4   >   r5   )r   r   r   r      r	      	   r	   r8   r   )r/   ranger   r   r    r!   )r"   r#   datacondensed_datar%   condensed_resultr'   r'   r(   test_deep_skip_rows6   s   r?   c                 C   sz   | }d}|j t|dd ddd}ttdddtdddtddd	gdd
}ttdddg d|d}t	|| d S )Nz^#foo,a,b,c
#foo,a,b,c

#foo,a,b,c
#foo,a,b,c

1/1/2000,1.,2.,3.
1/2/2000,4,5,6
1/3/2000,7,8,9
r	   r   Tr
   r   r   r   r   r   r   r   r   r   r   r   )r"   r#   r$   r<   r   r&   r'   r'   r(   test_skip_rows_blankF   s   
"r@   zdata,kwargs,expectedzKid,text,num_lines
1,"line 11
line 12",2
2,"line 21
line 22",2
3,"line 31",1r   )r   zline 21
line 22r   )r   zline 31r   idr$   	num_linesr   z+a,b,c
~a
 b~,~e
 d~,~f
 f~
1,2,~12
 13
 14~~r   )	quotecharr   )za
 bze
 dzf
 f)abczdText,url
~example
 sentence
 one~,url1
~example
 sentence
 two~,url2
~example
 sentence
 three~,url3r   zexample
 sentence
 twourl2Texturlc                 C   s*   | }|j t|fi |}t|| d S )Nr   r   r    r!   )r"   r<   kwargsr&   r#   r%   r'   r'   r(   test_skip_row_with_newlinea   s   $rO   c                 C   sL   | }d}g dg dg}t |g dd}|jt|dgd}t|| d S )NzYid,text,num_lines
1,"line '11' line 12",2
2,"line '21' line 22",2
3,"line '31' line 32",1)r   zline '21' line 22r   )r   zline '31' line 32r   rA   rD   r   r:   r   r   r   r    r!   )r"   r#   r<   exp_datar&   r%   r'   r'   r(   test_skip_row_with_quote   s   rR   zdata,exp_dataz\id,text,num_lines
1,"line 
'11' line 12",2
2,"line 
'21' line 22",2
3,"line 
'31' line 32",1)r   zline 
'21' line 22r   )r   zline 
'31' line 32r   z\id,text,num_lines
1,"line '11
' line 12",2
2,"line '21
' line 22",2
3,"line '31
' line 32",1)r   zline '21
' line 22r   )r   zline '31
' line 32r   zbid,text,num_lines
1,"line '11
' 	line 12",2
2,"line '21
' 	line 22",2
3,"line '31
' 	line 32",1)r   zline '21
' 	line 22r   )r   zline '31
' 	line 32r   c                 C   s8   | }|j t|dgd}t|g dd}t|| d S )Nr   r:   rA   rD   r   r   r   r    r!   )r"   r<   rQ   r#   r%   r&   r'   r'   r(   $test_skip_row_with_newline_and_quote   s   rT   lineterminator)r*   z
c           	      C   s   | }d g d}tg dg dg dgg dd}|jdkr/|d	kr/tjjd
d}|| |d|}d}tj	t
|dd |jt|ddg dd}W d    n1 sWw   Y  t|| d S )Nr*   )zSMOSMANIA ThetaProbe-ML2X z2007/01/01 01:00   0.2140 U M z2007/01/01 02:00   0.2141 M O z2007/01/01 04:00   0.2142 D M )
2007/01/01z01:00g1Zd?UM)rW   z02:00gk	g?rY   O)rW   z04:00gBfj?DrY   )datetimevarflagoflagrD   pythonrV   z+'CR' not respect with the Python parser yet)reasonz;The 'delim_whitespace' keyword in pd.read_csv is deprecatedF)matchcheck_stacklevelr   T)r   delim_whitespacenames)r/   r   enginepytestmarkxfailapplymarkerreplacer    assert_produces_warningFutureWarningr   r   r!   )	r"   rU   requestr#   r<   r&   ri   depr_msgr%   r'   r'   r(   test_skiprows_lineterminator   s6   	
	rq   c                 C   s8   | }d}t ddgi}|jt|dd}t|| d S )Nz	a"
b"
a
1rG   r   r   r:   rP   r"   r#   r<   r&   r%   r'   r'   r(   test_skiprows_infield_quote   s
   rs   zkwargs,expected1   foo)r   rf   c                 C   s6   | }d}|j t|fddd i|}t|| d S )Na
1
2
3
4
5r   c                 S   s   | d dkS )Nr   r   r'   xr'   r'   r(   <lambda>   s    z)test_skip_rows_callable.<locals>.<lambda>rM   )r"   rN   r&   r#   r<   r%   r'   r'   r(   test_skip_rows_callable   s   	r{   c                 C   sD   | }d}t ddgddgg}|jt|d dd d}t|| d S )	Nz0,a
1,b
2,c
3,d
4,er   rH   r   dc                 S   s   | dvS )N)r   r   r'   rx   r'   r'   r(   rz         z0test_skip_rows_callable_not_in.<locals>.<lambda>)r   r   rP   rr   r'   r'   r(   test_skip_rows_callable_not_in  s   r~   c                 C   sV   | }d}d}t jt|d |jt|dd d W d    d S 1 s$w   Y  d S )Nrw   zNo columns to parse from filerc   c                 S   s   dS )NTr'   rx   r'   r'   r(   rz     s    z)test_skip_rows_skip_all.<locals>.<lambda>r:   )rh   raisesr   r   r   )r"   r#   r<   msgr'   r'   r(   test_skip_rows_skip_all     "r   c                 C   sV   d}| }d}t jt|d |jt|dd d W d    d S 1 s$w   Y  d S )Nzby zerorw   r   c                 S   s   dd S )Nr   r   r'   rx   r'   r'   r(   rz   !  r}   z-test_skip_rows_bad_callable.<locals>.<lambda>r:   )rh   r   ZeroDivisionErrorr   r   )r"   r   r#   r<   r'   r'   r(   test_skip_rows_bad_callable  r   r   c                 C   sF   d}| }|j t|dg dd}tg dg dd}t|| d S )Nz$a,b
1,a
2,b
3,c
4,d
5,e
6,f
7,g
8,h
ru   )r   r7   r	   )nrowsr   )r   r   ru      r8   )rG   rI   egh)rG   rH   rS   )r"   r<   r#   r%   r&   r'   r'   r(   test_skip_rows_and_n_rows$  s
   
r   c                 C   sn   d}| }|j t||dd dd}t|}t|}t|tdg di t|tdg dig d	d
 d S )Nz%col_a
10
20
30
40
50
60
70
80
90
100
c                 S   s   | dv S )N)r   r7   ru   r'   rx   r'   r'   r(   rz   H  r}   z,test_skip_rows_with_chunks.<locals>.<lambda>r7   )rg   r   	chunksizecol_a)      <   F   )P   Z   d   )r7   ru   r	   )r   )r   r   nextr    r!   r   )r"   r<   r#   readerdf1df2r'   r'   r(   test_skip_rows_with_chunks7  s   $r   )%__doc__r   ior   numpyr   rh   pandas.errorsr   pandasr   r   pandas._testing_testingr    ri   usefixturesxfail_pyarrowfilterwarnings
pytestmarkparametrizelistr;   r)   r?   r@   rO   rR   rT   rq   rs   r{   r~   r   r   r   r   r'   r'   r'   r(   <module>   s    


!
	'



	
	
