o
    5c                     @   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eed	d	gd
d Zdd Z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d#d$ Zd%d& Zejd'd(g d)g d*gfd+g d,g d-gfd.g d/g d0gfgd1d2 Zejd3g d4d5d6 Zd7d8 Zejd9i e
d:dd;gifdd<gd=e
d<dd;gifgd>d? Zd@dA ZdBdC ZdDdE Z dFdG Z!dS )Hzj
Tests that skipped rows are properly handled during
parsing for all of the parsers defined in parsers.py
    )datetime)StringION)EmptyDataError)	DataFrameIndexpyarrow_skip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'   Z/var/www/html/gps/gps/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>7      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_rows3   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_blankB   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_newline\   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r0|d	kr0tjjd
d}|j| |d|}|j	t
|ddg dd}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)reasonr   T)r   delim_whitespacenames)r/   r   enginepytestmarkxfailnode
add_markerreplacer   r   r    r!   )r"   rU   requestr#   r<   r&   rg   r%   r'   r'   r(   test_skiprows_lineterminator   s,   	rm   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
   ro   zkwargs,expected1   foo)r   rd   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   rw   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'   rt   r'   r'   r(   rv          z0test_skip_rows_callable_not_in.<locals>.<lambda>)r   r   rP   rn   r'   r'   r(   test_skip_rows_callable_not_in   s   rz   c                 C   sV   | }d}d}t jt|d |jt|dd d W d    d S 1 s$w   Y  d S )Nrs   zNo columns to parse from filematchc                 S   s   dS )NTr'   rt   r'   r'   r(   rv     s    z)test_skip_rows_skip_all.<locals>.<lambda>r:   )rf   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 zerors   r{   c                 S   s   dd S )Nr   r   r'   rt   r'   r'   r(   rv     ry   z-test_skip_rows_bad_callable.<locals>.<lambda>r:   )rf   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
rq   )r   r7   r	   )nrowsr   )r   r   rq      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   )"__doc__r   ior   numpyr   rf   pandas.errorsr   pandasr   r   pandas._testing_testingr    rg   usefixtures
pytestmarkparametrizelistr;   r)   r?   r@   rO   rR   rT   rm   ro   rw   rz   r   r   r   r'   r'   r'   r(   <module>   s    


!
	
"

		