
    Mh                        S r SSKJr  SSKrSSKrSSKJr  SSKJ	r
  \R                  R                  SSS//5      S 5       r\R                  R                  S0 S	S
0SS0/5      S 5       rS rS rS r\R                  R                  S/ SQ5      S 5       r\R                  R                  SSS/5      S 5       rS rg)zf
Tests that comments are properly handled during parsing
for all of the parsers defined in parsers.py
    )StringION)	DataFrame	na_valuesNaNc                 n   U nSn[        / SQS[        R                  S/// SQS9nUR                  S:X  a?  Sn[        R
                  " [        US	9   UR                  [        U5      S
US9  S S S 5        g UR                  [        U5      S
US9n[        R                  " Xd5        g ! , (       d  f       g = f)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          U/var/www/html/env/lib/python3.13/site-packages/pandas/tests/io/parser/test_comment.pytest_commentr*      s    FD 	3-.H }}	!O]]:S1OOHTNC9OM 2__Xd^SI_NF&+	 21   B&&
B4read_kwargslineterminator*delim_whitespaceTc                 t   U nSnS nSnUR                  S5      (       a  UR                  SS5      n[        nO7UR                  S5      (       a!  UR                  SUR                  S5      5      nSUS	'   UR                  S
:X  ah  SU;   a  SnOSn[        R
                  " [        US9   [        R                  " XVSS9   UR                  " [        U5      40 UD6  S S S 5        S S S 5        g UR                  S:X  au  UR                  S5      (       a_  Sn[        R
                  " [        US9   [        R                  " XVSS9   UR                  " [        U5      40 UD6  S S S 5        S S S 5        g [        R                  " XVSS9   UR                  " [        U5      40 UD6nS S S 5        [        / SQS[        R                  S/// SQS9n	[        R                  " WU	5        g ! , (       d  f       GN= f! , (       d  f       g = f! , (       d  f       N= f! , (       d  f       g = f! , (       d  f       N= f)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++u >+> 2
 		(	"{7G'H'HO]]:S1++u >+> 2
 			#	#D5	Q$?;? 
R 	3-.H &(+)  21
 	  21
 		Q	QsT   (G6>G$G6-HH HH)$
G3	.G66
H
H	H
H&)
H7c                 n   U nSn[        / SQS[        R                  S/// SQS9nUR                  S:X  a?  Sn[        R
                  " [        US	9   UR                  [        U5      S
SS9  S S S 5        g UR                  [        U5      S
SS9n[        R                  " XS5        g ! , (       d  f       g = f)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OOHTNC!OD 2__Xd^S1_EF&+ 21r+   c                 n   U nSn[        / SQS[        R                  S/// SQS9nUR                  S:X  a?  Sn[        R
                  " [        US	9   UR                  [        U5      S
SS9  S S S 5        g UR                  [        U5      S
SS9n[        R                  " XS5        g ! , (       d  f       g = f)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OOHTNCOB 2__Xd^S_CF&+	 21r+   c                 r   U nSn[        / SQS[        R                  S/// SQS9nUR                  S:X  a@  Sn[        R
                  " [        US	9   UR                  [        U5      S
SSS9  S S S 5        g UR                  [        U5      S
SSS9n[        R                  " XS5        g ! , (       d  f       g = f)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OOHTNC!AON 2__Xd^S1Q_OF&+ 21s   B((
B6comment_char)r   ~&^r.   @c           	         U nSnUR                   S:X  aN  Sn[        R                  " [        US9   UR	                  [        UR                  SU5      5      US9  S S S 5        g UR	                  [        UR                  SU5      5      US9n[        / SQ/ SQ// S	QS
9n[        R                  " XV5        g ! , (       d  f       g = f)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<   2 	__c<01<  F )Y/IH&+ 21 	s   *B55
CrF   inferc                 |   U nSnUc  [        SS/SS/SS/S.5      nO[        / S	Q// S
QS9nUR                  S:X  a?  Sn[        R                  " [        US9   UR                  [        U5      SUS9  S S S 5        g UR                  [        U5      SUS9n[        R                  " Xd5        g ! , (       d  f       g = f)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OOHTNCOG 2__Xd^S_HF&+	 21s   B--
B;c                 :   U R                   S:X  a3  SnUR                  [        R                  R	                  U[
        S95        U nSnUR                   S:X  a?  Sn[        R                  " [        US9   UR                  [        U5      SS	S
9  S S S 5        g UR                  [        U5      SS	S
9n[        / SQ/ SQS[        R                  [        R                  /S[        R                  S/S.5      n[        R                  " Xg5        g ! , (       d  f       g = f)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OOHTNC6OJ 2__Xd^SF_KF"&&"&&)"&&$'		
H &+ 21s   3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   