
    bMh                        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                            dddgg          d             Zej                            di d	d
iddig          d             Zd Zd Zd Zej                            dg d          d             Zej                            dddg          d             Zd ZdS )zf
Tests that comments are properly handled during parsing
for all of the parsers defined in parsers.py
    )StringION)	DataFrame	na_valuesNaNc                    | }d}t          g ddt          j        dggg d          }|j        dk    r\d}t	          j        t          |	          5  |                    t          |          d
|           d d d            n# 1 swxY w Y   d S |                    t          |          d
|          }t          j
        ||           d S )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          c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pandas/tests/io/parser/test_comment.pytest_commentr*      s'   FD 	3-.  H }	!!O]:S111 	N 	NOOHTNNC9OMMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N__Xd^^SI_NNF&(+++++   &BB
Bread_kwargslineterminator*delim_whitespaceTc                 p   | }d}d }d}|                     d          r|                    dd          }t          }n>|                     d          r)|                    d|                     d                    }d|d	<   |j        d
k    rd|v rd}nd}t	          j        t          |          5  t          j        ||d          5   |j	        t          |          fi | d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S |j        dk    r|                     d          rd}t	          j        t          |          5  t          j        ||d          5   |j	        t          |          fi | d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S t          j        ||d          5   |j	        t          |          fi |}d d d            n# 1 swxY w Y   t          g ddt          j        dggg d          }	t          j        ||	           d S )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)** E||C%%	)	*	* E||D+//2B"C"CDD K	}	!!{**X C TC]:S111 	? 	?+Hu   ? ?  >>+>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?
 		(	"	"{7G'H'H	"O]:S111 	? 	?+Hu   ? ?  >>+>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?
 			#D5	Q	Q	Q @ @ $??;??@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 	3-.  H &(+++++s~   .DC."D.C2	2D5C2	6DD	D	F&'FF&F	F&F	F&&F*-F*
G22G69G6c                    | }d}t          g ddt          j        dggg d          }|j        dk    r\d}t	          j        t          |	          5  |                    t          |          d
d           d d d            n# 1 swxY w Y   d S |                    t          |          d
d          }t          j
        ||           d S )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11 	E 	EOOHTNNC!ODDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E__Xd^^S1_EEF&(+++++r+   c                    | }d}t          g ddt          j        dggg d          }|j        dk    r\d}t	          j        t          |	          5  |                    t          |          d
d           d d d            n# 1 swxY w Y   d S |                    t          |          d
d          }t          j
        ||           d S )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11 	C 	COOHTNNCOBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C__Xd^^S_CCF&(+++++r+   c                    | }d}t          g ddt          j        dggg d          }|j        dk    r]d}t	          j        t          |	          5  |                    t          |          d
dd           d d d            n# 1 swxY w Y   d S |                    t          |          d
dd          }t          j
        ||           d S )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11 	O 	OOOHTNNC!AONNN	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O__Xd^^S1Q_OOF&(+++++s   'BBBcomment_char)r   ~&^r.   @c           	         | }d}|j         dk    rod}t          j        t          |          5  |                    t          |                    d|                    |           d d d            n# 1 swxY w Y   d S |                    t          |                    d|                    |          }t          g dg dgg d	
          }t          j	        ||           d S )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      s6   F;D}	!!O]:S111 	 	OOc<8899<    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	__c<0011<   F )))YYY/IIIH&(+++++s   9A22A69A6rF   inferc                    | }d}|t          ddgddgddgd          }nt          g d	gg d
          }|j        dk    r\d}t          j        t          |          5  |                    t          |          d|           d d d            n# 1 swxY w Y   d S |                    t          |          d|          }t          j        ||           d S )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JKKiii[///BBB}	!!O]:S111 	H 	HOOHTNNCOGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H__Xd^^S_HHF&(+++++s   &BBBc                 T   | j         dk    r;d}|                    t          j                            |t
                               | }d}|j         dk    r\d}t          j        t          |          5  |                    t          |          dd	
           d d d            n# 1 swxY w Y   d S |                    t          |          dd	
          }t          g dg ddt          j        t          j        gdt          j        dgd          }t          j        ||           d S )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      sx   S  PFK--VN-SSTTTF	 	 }	!!O]:S111 	K 	KOOHTNNC6OJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K__Xd^^SF_KKFIIII"&"&)"&$'		
 	
 H &(+++++s   3&B%%B),B))__doc__ior   numpyr   r   pandasr   pandas._testing_testingr!   ri   parametrizer*   r=   rB   rG   rI   rY   r_   rl        r)   <module>rv      s                           teWo66, , 76,$ B)3/2Dd1KL ., ., .,b, , ,0, , ,,, , ,6 )G)G)GHH, , IH,& GT?33, , 43,&, , , , ,ru   