
    A>i                        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          b/var/www/html/land-tabula/venv/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*sepz\s+c                 B   U nSnUR                  S5      (       a  UR                  SS5      nO7UR                  S5      (       a!  UR                  SUR                  S5      5      nSUS'   UR                  S	:X  aJ  SU;   a  S
nOSn[        R                  " [
        US9   UR                  " [        U5      40 UD6  S S S 5        g UR                  S:X  aW  UR                  S5      (       aA  Sn[        R                  " [
        US9   UR                  " [        U5      40 UD6  S S S 5        g UR                  " [        U5      40 UD6n[        / SQS[        R                  S/// SQS9n[        R                  " XV5        g ! , (       d  f       g = f! , (       d  f       g = f)Nz@# empty
A,B,C
1,2.,4.#hello world
#ignore this line
5.,NaN,10.0
r/   , r-   
r   r   r   zFThe 'lineterminator' option is not supported with the 'pyarrow' enginer   r   pythonz>Custom line terminators not supported in python parser \(yet\)r   r
   r   r   r   )getreplacer   r   r   r   r    r   r   r   r   r!   r"   )r#   r,   r$   r%   r'   r(   r&   s          r)   test_line_commentr7   "   s[   FD u||C%	)	*	*||D+//2B"CD K	}}	!{*X  TC]]:S1OOHTN:k: 2	(	"{7G'H'HO]]:S1OOHTN:k: 2__Xd^;{;F	3-.H &+ 21 21s   E?F?
F
F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_skiprowsr<   H   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   r;   s         r)   test_comment_headerrA   `   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   r9   r>   )r   r:   r@   r   r;   s         r)   test_comment_skiprows_headerrC   v   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   r>         )r9         abcr   )
r   r   r   r   r    r   r6   r   r!   r"   )r#   rD   r$   r%   r'   r(   r&   s          r)   test_custom_comment_charrS      s    F;D}}	!O]]:S1OOc<89<   2 	__c<01<  F )Y/IH&+ 21 	s   *B55
Cr@   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,3rP   1rQ   2rR   3)r   r>   rK   rJ   rO   r   r   r   r   r   r?   )	r   r   r   r   r   r    r   r!   r"   )r#   r@   r$   r%   r&   r'   r(   s          r)   test_comment_first_linerY      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)NrR   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   )r>   r9      )rK   rM      g      @r	   g      &@)col1col2col3col4)r   applymarkerr   markxfailAssertionErrorr   r   r    r   r   r   r   r!   r"   )r#   requestr[   r$   r%   r'   r(   r&   s           r)   "test_comment_char_in_default_valuerg      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!   rc   parametrizer*   r7   r<   rA   rC   rS   rY   rg        r)   <module>rq      s   
      teWo6, 7,$ .>-Dufo(VW", X",J,0,,,6 )GH, I,& GT?3, 4,&,rp   