U
    ½mœd   ã                	   @   sâ   d dl mZ d dlZd dlZd dlmZmZmZmZ ej	 
dddddgd	d
gfddddgd	gfddddgg fg¡dd„ ƒZdd„ Zej	 
deeg¡dd„ ƒZej	 
deeg¡dd„ ƒZej	 
dejeej	jd�eg¡dd„ ƒZdS )é    )ÚBytesION)Ú_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              
   C   s²   t  d¡}| dddgdddgdddgdddgdd	d
gdd	d
gdœ¡}t|| |ƒ\}}t||jƒsft‚t|ƒdkr„t||jƒs®t‚n*t|ƒdkr¢t||jƒs®t‚n|dks®t‚dS )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   N)ÚpytestÚimportorskipZ	DataFramer   Ú
isinstanceÚAssertionErrorÚlenÚSeries)Úfeature_namesÚtarget_namesÚpdZ
X_originalÚXÚy© r   ú`/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/datasets/tests/test_arff_parser.pyÚtest_post_process_frame   s"    "
úÿr!   c               	   C   s4   d} t jt| d�� tddddddƒ W 5 Q R X dS )z3An error will be raised if the parser is not known.z8Unknown parser: 'xxx'. Should be 'liac-arff' or 'pandas')ÚmatchZxxxN)r   ZraisesÚ
ValueErrorr   )Úerr_msgr   r   r    Ú*test_load_arff_from_gzip_file_error_parserG   s    r%   Úparser_funcc           	      C   sÌ   t  d¡}tt d¡ d¡ƒ}dddœdddœdd	dœd
ddœdœ}ddd	g}dg}d| tkrbdnd| tkrpdndddœ}| |d|||d�\}}}}|j ¡ || ksªt	‚|j
 |jd |j|dd�¡ dS )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©Z	data_typeÚnameÚstringÚstr_single_quoteÚstr_nested_quoteÚnumericÚclass)r)   r-   r.   r0   ÚAú	some textz'some text'z"expect double quotes"z'"expect double quotes"'r   ©Zoutput_arrays_typeZopenml_columns_infoZfeature_names_to_selectZtarget_names_to_select©r+   N)r   r   r   ÚtextwrapÚdedentÚencoder   ÚcolumnsÚtolistr   ÚtestingÚassert_series_equalÚilocr   ©	r&   r   Z	arff_fileZcolumns_infor   r   Zexpected_valuesÚ_Úframer   r   r    Ú+test_pandas_arff_parser_strip_single_quotesQ   sT    
ÿ
öÿþþþþóýÿöûr@   c           	      C   s´   t  d¡}tt d¡ d¡ƒ}dddœdddœdd	dœd
ddœdœ}ddd	g}dg}dddddœ}| |d|||d�\}}}}|j ¡ || ks’t‚|j	 
|jd |j|dd�¡ dS )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_quoter*   r,   Ústr_double_quoter.   r/   r0   )rA   rB   r.   r0   r1   r2   z'expect double quotes'r   r3   r4   N©r   r   r   r5   r6   r7   r8   r9   r   r:   r;   r<   r   r=   r   r   r    Ú+test_pandas_arff_parser_strip_double_quotes˜   sP    
ÿ
öÿþþþþóýüûrD   )Zmarksc           	      C   s´   t  d¡}tt d¡ d¡ƒ}dddœdddœdd	dœd
ddœdœ}ddd	g}dg}dddddœ}| |d|||d�\}}}}|j ¡ || ks’t‚|j	 
|jd |j|dd�¡ dS )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_quoter*   r,   Ústr_without_quoteÚstr_internal_quoter/   r0   )rE   rF   rG   r0   r1   r2   z'internal' quoter   r3   r4   NrC   r=   r   r   r    Ú'test_pandas_arff_parser_strip_no_quotesØ   sP    

ÿ
öÿþþþþóýüûrH   )Úior   r5   r   Zsklearn.datasets._arff_parserr   r   r   r   ÚmarkZparametrizer!   r%   r@   rD   ÚparamZxfailrH   r   r   r   r    Ú<module>   sR   üùüùüùíþ 


F
?ýþ