
    Owg                        d Z ddlmZ ddlZddlZddlmZ ddlm	Z
 ej                  j                  dddgg      d        Zej                  j                  di d	d
iddig      d        Zd Zd Zd Zej                  j                  dg d      d        Zej                  j                  dddg      d        Zd Zy)zf
Tests that comments are properly handled during parsing
for all of the parsers defined in parsers.py
    )StringION)	DataFrame	na_valuesNaNc                 x   | }d}t        g ddt        j                  dggg d      }|j                  dk(  rDd}t	        j
                  t        |	      5  |j                  t        |      d
|       d d d        y |j                  t        |      d
|      }t        j                  ||       y # 1 sw Y   y xY w)Nz&A,B,C
1,2.,4.#hello world
5.,NaN,10.0
g      ?g       @      @      @      $@ABCcolumnspyarrow?The 'comment' option is not supported with the 'pyarrow' enginematch#commentr   r   npnanenginepytestraises
ValueErrorread_csvr   tmassert_frame_equal)all_parsersr   parserdataexpectedmsgresults          Z/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/io/parser/test_comment.pytest_commentr*      s    FD 	3-.H }}	!O]]:S1 	NOOHTNC9OM	N__Xd^SI_NF&(+		N   B00B9read_kwargslineterminator*delim_whitespaceTc                 :   | }d}d }d}|j                  d      r|j                  dd      }t        }n2|j                  d      r!|j                  d|j                  d            }d|d	<   |j                  d
k(  rkd|v rd}nd}t	        j
                  t        |      5  t        j                  ||d      5   |j                  t        |      fi | d d d        d d d        y |j                  dk(  ru|j                  d      rdd}t	        j
                  t        |      5  t        j                  ||d      5   |j                  t        |      fi | d d d        d d d        y t        j                  ||d      5   |j                  t        |      fi |}d d d        t        g ddt        j                  dggg d      }	t        j                  |	       y # 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   uxY w)Nz@# empty
A,B,C
1,2.,4.#hello world
#ignore this line
5.,NaN,10.0
z;The 'delim_whitespace' keyword in pd.read_csv is deprecatedr/   , r-   
r   r   r   zFThe 'lineterminator' option is not supported with the 'pyarrow' enginer   r   F)r   check_stacklevelpythonz>Custom line terminators not supported in python parser \(yet\)r   r
   r   r   r   )getreplaceFutureWarningr   r   r   r   r!   assert_produces_warningr    r   r   r   r   r"   )
r#   r,   requestr$   r%   warndepr_msgr'   r(   r&   s
             r)   test_line_commentr=   !   s    FD DLH)*||C%	)	*||D+//2B"CD K	}}	!{*X  TC]]:S1 	?++Hu ?  >+>?	?
 		(	"{7G'HO]]:S1 	?++Hu ?  >+>?	?
 			#	#D5	Q @ $?;?@ 	3-.H &(+)? ?	?
 	? ?	?
 	@ @sT   G-6G G-!H:G9H H G*	%G--G69H	>HHHc                 x   | }d}t        g ddt        j                  dggg d      }|j                  dk(  rDd}t	        j
                  t        |	      5  |j                  t        |      d
d       d d d        y |j                  t        |      d
d      }t        j                  ||       y # 1 sw Y   y xY w)NzH# empty
random line
# second empty line
1,2,3
A,B,C
1,2.,4.
5.,NaN,10.0
r   r
   r   r   r   r   r   r   r      )r   skiprowsr   r#   r$   r%   r&   r'   r(   s         r)   test_comment_skiprowsrB   U   s    FD 	3-.H }}	!O]]:S1 	EOOHTNC!OD	E__Xd^S1_EF&(+	Er+   c                 x   | }d}t        g ddt        j                  dggg d      }|j                  dk(  rDd}t	        j
                  t        |	      5  |j                  t        |      d
d       d d d        y |j                  t        |      d
d      }t        j                  ||       y # 1 sw Y   y xY w)Nz<# empty
# second empty line
1,2,3
A,B,C
1,2.,4.
5.,NaN,10.0
r   r
   r   r   r   r   r   r   r      r   headerr   rA   s         r)   test_comment_headerrG   m   s    FD 	3-.H }}	!O]]:S1 	COOHTNCOB	C__Xd^S_CF&(+		Cr+   c                 |   | }d}t        g ddt        j                  dggg d      }|j                  dk(  rEd}t	        j
                  t        |	      5  |j                  t        |      d
dd       d d d        y |j                  t        |      d
dd      }t        j                  ||       y # 1 sw Y   y xY w)NzU# empty
# second empty line
# third empty line
X,Y,Z
1,2,3
A,B,C
1,2.,4.
5.,NaN,10.0
r   r
   r   r   r   r   r   r   r   r?   rD   )r   r@   rF   r   rA   s         r)   test_comment_skiprows_headerrI      s    FD 	3-.H }}	!O]]:S1 	OOOHTNC!AON	O__Xd^S1Q_OF&(+	Os   B22B;comment_char)r   ~&^r.   @c           	         | }d}|j                   dk(  rSd}t        j                  t        |      5  |j	                  t        |j                  d|            |       d d d        y |j	                  t        |j                  d|            |      }t        g dg dgg d	
      }t        j                  ||       y # 1 sw Y   y xY w)Nz,a,b,c
1,2,3#ignore this!
4,5,6#ignorethistoor   r   r   r   )r   rD         )r?         abcr   )
r   r   r   r   r    r   r7   r   r!   r"   )r#   rJ   r$   r%   r'   r(   r&   s          r)   test_custom_comment_charrY      s    F;D}}	!O]]:S1 	OOc<89<  	 	__c<01<  F )Y/IH&(+	 	s   -B??CrF   inferc                    | }d}|t        ddgddgddgd      }nt        g d	gg d
      }|j                  dk(  rDd}t        j                  t        |      5  |j                  t        |      d|       d d d        y |j                  t        |      d|      }t        j                  ||       y # 1 sw Y   y xY w)Nz # notes
a,b,c
# more notes
1,2,3rV   1rW   2rX   3)r   rD   rQ   rP   rU   r   r   r   r   r   rE   )	r   r   r   r   r   r    r   r!   r"   )r#   rF   r$   r%   r&   r'   r(   s          r)   test_comment_first_liner_      s     F0D~#sc
SzJKi[/B}}	!O]]:S1 	HOOHTNCOG	H__Xd^S_HF&(+		Hs   B66B?c                 B   | j                   dk(  r6d}|j                  t        j                  j	                  |t
                     | }d}|j                   dk(  rDd}t        j                  t        |      5  |j                  t        |      dd	
       d d d        y |j                  t        |      dd	
      }t        g dg ddt        j                  t        j                  gdt        j                  dgd      }t        j                  ||       y # 1 sw Y   y xY w)NrX   z=see gh-34002: works on the python engine but not the c engine)reasonr   zU# this is a comment
col1,col2,col3,col4
1,2,3,4#inline comment
4,5#,6,10
7,8,#N/A,11
r   r   r   r   z#N/Ar   )rD   r?      )rQ   rS      g      @r	   g      &@)col1col2col3col4)r   applymarkerr   markxfailAssertionErrorr   r   r    r   r   r   r   r!   r"   )r#   r:   ra   r$   r%   r'   r(   r&   s           r)   "test_comment_char_in_default_valuerl      s    S PFKK--VN-STF	 	 }}	!O]]:S1 	KOOHTNC6OJ	K__Xd^SF_KF"&&"&&)"&&$'		
H &(+	Ks   6DD)__doc__ior   numpyr   r   pandasr   pandas._testing_testingr!   ri   parametrizer*   r=   rB   rG   rI   rY   r_   rl        r)   <module>rv      s         teWo6, 7,$ B)3/2Dd1KL.,.,b,0,,,6 )GH, I,& GT?3, 4,&,ru   