
    {Kg                         d dl Z d dlmZ d dlZd dlmZmZmZmZ ej                  j                  dg dddgfg ddgfg dg fg      d        Zd	 Zej                  j                  d
eeg      d        Zej                  j                  d
eeg      d        Zej                  j                  d
 ej                  eej                  j                         eg      d        Zy)    N)BytesIO)_liac_arff_parser_pandas_arff_parser_post_process_frameload_arff_from_gzip_filezfeature_names, target_names)col_int_as_integercol_int_as_numericcol_float_as_realcol_float_as_numericcol_categorical
col_stringc           	      j   t        j                  d      }|j                  g dg dg dg dg dg dd      }t        || |      \  }}t	        ||j                        sJ t        |      dk\  rt	        ||j                        sJ yt        |      dk(  rt	        ||j                        sJ y|J y)	zNCheck the behaviour of the post-processing function for splitting a dataframe.pandas)         )g      ?g       @g      @)abc)r   r	   r
   r   r   r   r   r   N)pytestimportorskip	DataFramer   
isinstancelenSeries)feature_namestarget_namespd
X_originalXys         k/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/sklearn/datasets/tests/test_arff_parser.pytest_post_process_framer#      s    D 
		X	&B"+"+!0$3.)	
	J z=,GDAqa&&&
<A!R\\***	\	a	!RYY'''yy    c            	          d} t        j                  t        |       5  t        dddddd       ddd       y# 1 sw Y   yxY w)z3An error will be raised if the parser is not known.z8Unknown parser: 'xxx'. Should be 'liac-arff' or 'pandas')matchxxxN)r   raises
ValueErrorr   )err_msgs    r"   *test_load_arff_from_gzip_file_error_parserr+   G   s6    
 IG	z	1 ueUEJ 
2	1	1s	   8Aparser_funcc                    t        j                  d      }t        t        j                  d      j                  d            }dddddddd	dd
ddd}g d}dg}d| t        u rdnd| t        u rdnddd} | |d|||      \  }}}}|j                  j                         ||z   k(  sJ |j                  j                  |j                  d   |j                  |d             y)z9Check that we properly strip single quotes from the data.r   a5  
            @relation 'toy'
            @attribute 'cat_single_quote' {'A', 'B', 'C'}
            @attribute 'str_single_quote' string
            @attribute 'str_nested_quote' string
            @attribute 'class' numeric
            @data
            'A','some text','"expect double quotes"',0
            utf-8nominalcat_single_quote	data_typenamestringstr_single_quotestr_nested_quotenumericclass)r0   r5   r6   r8   )r0   r5   r6   A	some textz'some text'z"expect double quotes"z'"expect double quotes"'r   output_arrays_typeopenml_columns_infofeature_names_to_selecttarget_names_to_selectr3   N)r   r   r   textwrapdedentencoder   columnstolisttestingassert_series_equalilocr   	r,   r   	arff_filecolumns_infor   r   expected_values_frames	            r"   +test_pandas_arff_parser_strip_single_quotesrO   Q   s#    
		X	&B
	
 &/I  #&

 "&

 "&

 #
L&M
 9L  &*;;K // %-O !#( -+NAq% ==!]\%AAAAJJ""5::a="))ORS)2TUr$   c                    t        j                  d      }t        t        j                  d      j                  d            }dddddddd	dd
ddd}g d}dg}ddddd} | |d|||      \  }}}}|j                  j                         ||z   k(  sJ |j                  j                  |j                  d   |j                  |d             y)z9Check that we properly strip double quotes from the data.r   a5  
            @relation 'toy'
            @attribute 'cat_double_quote' {"A", "B", "C"}
            @attribute 'str_double_quote' string
            @attribute 'str_nested_quote' string
            @attribute 'class' numeric
            @data
            "A","some text","'expect double quotes'",0
            r.   r/   cat_double_quoter1   r4   str_double_quoter6   r7   r8   )rQ   rR   r6   r8   )rQ   rR   r6   r9   r:   z'expect double quotes'r   r;   r@   Nr   r   r   rA   rB   rC   rD   rE   rF   rG   rH   r   rI   s	            r"   +test_pandas_arff_parser_strip_double_quotesrT      s	    
		X	&B
	
 &/I  #&

 "&

 "&

 #
L&M
 9L  '4	O !#( -+NAq% ==!]\%AAAAJJ""5::a="))ORS)2TUr$   )marksc                    t        j                  d      }t        t        j                  d      j                  d            }dddddddd	dd
ddd}g d}dg}ddddd} | |d|||      \  }}}}|j                  j                         ||z   k(  sJ |j                  j                  |j                  d   |j                  |d             y)z7Check that we properly parse with no quotes characters.r   a'  
            @relation 'toy'
            @attribute 'cat_without_quote' {A, B, C}
            @attribute 'str_without_quote' string
            @attribute 'str_internal_quote' string
            @attribute 'class' numeric
            @data
            A,some text,'internal' quote,0
            r.   r/   cat_without_quoter1   r4   str_without_quotestr_internal_quoter7   r8   )rW   rX   rY   r8   )rW   rX   rY   r9   r:   z'internal' quoter   r;   r@   NrS   rI   s	            r"   'test_pandas_arff_parser_strip_no_quotesrZ      s	    
		X	&B
	
 &/I  #'

 "'

 "(

 #
L&M
 9L !(0	O !#( -+NAq% ==!]\%AAAAJJ""5::a="))ORS)2TUr$   )rA   ior   r   sklearn.datasets._arff_parserr   r   r   r   markparametrizer#   r+   rO   rT   paramxfailrZ    r$   r"   <module>rb      s0       ! -	
 	
 	
'@A@2K ):<O(PQCV RCVL ):<O(PQ<V R<V~  	&fkk.?.?@<V<Vr$   