a
    h!z                     @   s<  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlZd dlmZmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z  d d
l!m"Z" d dl#m$Z$ d dl%m&Z&m'Z' d dl(m)Z)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0m1Z1 d dl2m3Z3m4Z4 G dd deZ5G dd deZ6G dd deZ7G dd deZ8G dd deZ9G dd de8Z:G dd de8e9Z;G d d! d!e;Z<G d"d# d#eZ=G d$d% d%eZ>G d&d' d'Z?G d(d) d)eZ@d*d+ ZAd,d- ZBd.d/ ZCd0d1 ZDd2d3 ZEd4d5 ZFd6d7 ZGd8d9 ZHd:d; ZId<d= ZJd>d? ZKd@dA ZLdBdC ZMejNOdDe& dEfe e& dFdGdHgidEfe"dIe& fgdEfe"dJe e& dFdGdHgifgdEfe' dKfe e' dFdGdHgidKfe"dLe' fgdKfe"dMe e' dFdGdHgifgdKfgdNdO ZPejNOdDe' dEfe e' dFdGdHgidEfe"dLe' fgdEfe"dMe e' dFdGdHgifgdEfe& dKfe e& dFdGdHgidKfe"dIe& fgdKfe"dJe e& dFdGdHgifgdKfgdPdQ ZQejNOdDe dEfe e dRdSdTgidEfe"dUe fgdEfe"dVe e dRdSdTgifgdEfe& dKfe e& dFdGdHgidKfe"dIe& fgdKfe"dJe e& dFdGdHgifgdKfgdWdX ZRdYdZ ZSd[d\ ZTd]d^ ZUejNOd_e)d`d daejVd dbfe*d`d daejWd dbfgdcdd ZXdedf ZYdgdh ZZdidj Z[G dkdl dle)Z\dmZ]dndo Z^G dpdq dqe)Z_drds Z`dtdu ZaG dvdw dwZbG dxdy dyebeZcdzd{ Zdd|d} ZeG d~d deZfdd Zgdd Zhdd Zidd Zjdd Zkdd Zldd Zmdd Zndd Zodd ZpG dd dZqG dd deqeZrejNOde er gdd Zsdd ZtejNOdg ddd ZuedEddd ZvedEddd ZwdS )    N)assert_allclose)config_contextdatasets)BaseEstimatorOutlierMixinTransformerMixincloneis_classifieris_clustereris_outlier_detectoris_regressor)KMeans)PCA)IsolationForest)InconsistentVersionWarning)GridSearchCV)Pipeline)StandardScaler)SVCSVR)DecisionTreeClassifierDecisionTreeRegressor)MockDataFrame)_get_output_config)_convert_containerassert_array_equal)_check_n_featuresvalidate_datac                   @   s   e Zd ZdddZdS )MyEstimatorr   Nc                 C   s   || _ || _d S N)l1empty)selfr    r!    r#   S/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/tests/test_base.py__init__.   s    zMyEstimator.__init__)r   N__name__
__module____qualname__r%   r#   r#   r#   r$   r   -   s   r   c                   @   s   e Zd ZdddZdS )KNc                 C   s   || _ || _d S r   )cd)r"   r+   r,   r#   r#   r$   r%   4   s    z
K.__init__)NNr&   r#   r#   r#   r$   r*   3   s   r*   c                   @   s   e Zd ZdddZdS )TNc                 C   s   || _ || _d S r   )ab)r"   r.   r/   r#   r#   r$   r%   :   s    z
T.__init__)NNr&   r#   r#   r#   r$   r-   9   s   r-   c                       s   e Zd Z fddZ  ZS )NaNTagc                    s   t   }d|j_|S )NTsuper__sklearn_tags__
input_tags	allow_nanr"   tags	__class__r#   r$   r3   @   s    
zNaNTag.__sklearn_tags__r'   r(   r)   r3   __classcell__r#   r#   r8   r$   r0   ?   s   r0   c                       s   e Zd Z fddZ  ZS )NoNaNTagc                    s   t   }d|j_|S NFr1   r6   r8   r#   r$   r3   G   s    
zNoNaNTag.__sklearn_tags__r:   r#   r#   r8   r$   r<   F   s   r<   c                       s   e Zd Z fddZ  ZS )OverrideTagc                    s   t   }d|j_|S r=   r1   r6   r8   r#   r$   r3   N   s    
zOverrideTag.__sklearn_tags__r:   r#   r#   r8   r$   r>   M   s   r>   c                   @   s   e Zd ZdS )DiamondOverwriteTagNr'   r(   r)   r#   r#   r#   r$   r?   T   s   r?   c                   @   s   e Zd ZdS )InheritDiamondOverwriteTagNr@   r#   r#   r#   r$   rA   X   s   rA   c                   @   s$   e Zd ZdZedgfddZdS )ModifyInitParamsz_Deprecated behavior.
    Equal parameters but with a type cast.
    Doesn't fulfill a is a
    r   c                 C   s   |  | _d S r   )copyr.   r"   r.   r#   r#   r$   r%   b   s    zModifyInitParams.__init__N)r'   r(   r)   __doc__nparrayr%   r#   r#   r#   r$   rB   \   s   rB   c                   @   s   e Zd ZdZdddZdS )Buggyz9A buggy estimator that does not set its parameters right.Nc                 C   s
   d| _ d S )N   r.   rD   r#   r#   r$   r%   i   s    zBuggy.__init__)Nr'   r(   r)   rE   r%   r#   r#   r#   r$   rH   f   s   rH   c                   @   s(   e Zd Zdd ZdddZd	ddZdS )
NoEstimatorc                 C   s   d S r   r#   r"   r#   r#   r$   r%   n   s    zNoEstimator.__init__Nc                 C   s   | S r   r#   r"   Xyr#   r#   r$   fitq   s    zNoEstimator.fitc                 C   s   d S r   r#   r"   rO   r#   r#   r$   predictt   s    zNoEstimator.predict)NN)N)r'   r(   r)   r%   rQ   rS   r#   r#   r#   r$   rL   m   s   
rL   c                   @   s   e Zd ZdZdd ZdS )VargEstimatorz-scikit-learn estimators shouldn't have vargs.c                 G   s   d S r   r#   )r"   Zvargsr#   r#   r$   r%   {   s    zVargEstimator.__init__NrK   r#   r#   r#   r$   rT   x   s   rT   c                  C   sn   ddl m} m} | |dd}t|}||us0J | | ksDJ | |tdd}t|}||usjJ d S )Nr   	SelectFpr	f_classif皙?alpha)
      )sklearn.feature_selectionrV   rW   r   
get_paramsrF   ZzerosrV   rW   selectorZnew_selectorr#   r#   r$   
test_clone   s    ra   c                  C   s<   ddl m} m} | |dd}d|_t|}t|dr8J d S )Nr   rU   rX   rY   testown_attribute)r]   rV   rW   rc   r   hasattrr_   r#   r#   r$   test_clone_2   s
    re   c                  C   s   t  } d| _tt t|  W d    n1 s40    Y  t }tt t| W d    n1 sl0    Y  t }tt t| W d    n1 s0    Y  t	 }tt t| W d    n1 s0    Y  d S )Nr\   )
rH   r.   pytestraisesRuntimeErrorr   rL   	TypeErrorrT   rB   )ZbuggyZno_estimatorZvarg_estestr#   r#   r$   test_clone_buggy   s    &&&rk   c                  C   s^   t tg d} t| }t| j|j t ttdggd} t| }t| jj|jj d S )Nr!   r   )	r   rF   rG   r   r   r!   spZ
csr_matrixdataclfZclf2r#   r#   r$   test_clone_empty_array   s    rq   c                  C   s(   t tjd} t| }| j|ju s$J d S Nrl   )r   rF   nanr   r!   ro   r#   r#   r$   test_clone_nan   s    rt   c                  C   s*   dt  i} t| }| d |d us&J d S )Nr.   )r   r   )origZclonedr#   r#   r$   test_clone_dict   s    
rv   c                     sn    fddt tD } | D ]N  td}t|d}t|}|jj|jju sRJ t|j	 |j	  qd S )Nc                    s0   g | ](}| d rttt|  tu r qS )Z_matrix)endswithtypegetattrrm   ).0nameclsr#   r$   
<listcomp>   s    z.test_clone_sparse_matrices.<locals>.<listcomp>   rl   )
dirrm   rF   eyer   r   r!   r9   r   Ztoarray)Zsparse_matrix_classesZsparse_matrixrp   Z
clf_clonedr#   r|   r$   test_clone_sparse_matrices   s    

r   c                  C   s&   t t d} t| }| j|ju s"J d S rr   )r   r   r!   ro   r#   r#   r$   test_clone_estimator_types   s    
r   c                  C   s>   d} t jt| d tt W d    n1 s00    Y  d S )Nz8You should provide an instance of scikit-learn estimatormatch)rf   rg   ri   r   r   )msgr#   r#   r$   %test_clone_class_rather_than_instance   s    r   c                  C   sT   t  } t|  tt t }t|dks,J tdgd d}tt|dksPJ d S )NzT(a=K(), b=K())Zlong_paramsi  rJ   i  )r   reprr-   r*   len)my_estimatorrb   Zsome_estr#   r#   r$   	test_repr   s    r   c                  C   s   t  } t|  d S r   )r   str)r   r#   r#   r$   test_str   s    r   c                  C   s   t t t} d| jddv s J d| jddvs4J | jdd | jjdksPJ tt | jdd W d    n1 s|0    Y  d S )Na__dT)deepFr\   )r   )Za__a)	r-   r*   r^   
set_paramsr.   r,   rf   rg   
ValueError)rb   r#   r#   r$   test_get_params  s    r   c                   C   s   t jtdd ttsJ W d    n1 s00    Y  t jtdd ttsVJ W d    n1 sj0    Y  t jtdd ttsJ W d    n1 s0    Y  t jtdd t	t
sJ W d    n1 s0    Y  d S )Nz!passing a class to.*is deprecatedr   )rf   warnsFutureWarningr	   r   r   r   r
   r   r   r   r#   r#   r#   r$   test_is_estimator_type_class  s    ***r   zestimator, expected_resultTCrX   rI   svcZsvc_cvFZsvrZsvr_cvc                 C   s   t | |ksJ d S r   )r	   	estimatorZexpected_resultr#   r#   r$   test_is_classifier  s    r   c                 C   s   t | |ksJ d S r   )r   r   r#   r#   r$   test_is_regressor/  s    r   Z
n_clusters      kmZkm_cvc                 C   s   t | |ksJ d S r   )r
   r   r#   r#   r$   test_is_clusterer@  s    r   c                  C   s   t dt fg} tt | jdd W d    n1 s<0    Y  tt | jdd W d    n1 sr0    Y  d S )Nr   T)Zsvc__stupid_param)Zsvm__stupid_param)r   r   rf   rg   r   r   )rp   r#   r#   r$   test_set_paramsQ  s
    *r   c                     sR   G  fdddt } ddd td|  fgt|  i fD ]}|jddd q:d S )Nc                       s   e Zd Z fddZ  ZS )z?test_set_params_passes_all_parameters.<locals>.TestDecisionTreec                    s"   t  jf i | |ksJ | S r   )r2   r   )r"   kwargs)r9   expected_kwargsr#   r$   r   h  s    zJtest_set_params_passes_all_parameters.<locals>.TestDecisionTree.set_params)r'   r(   r)   r   r;   r#   r   r8   r$   TestDecisionTreeg  s   r   r   r\   )	max_depthZmin_samples_leafr   )Zestimator__max_depthZestimator__min_samples_leaf)r   r   r   r   )r   rj   r#   r   r$   %test_set_params_passes_all_parametersc  s    

r   c                  C   s0   t t i } | jt dd | jjdks,J d S )Ng      E@)r   Zestimator__C)r   r   r   r   r   r   )Zgscvr#   r#   r$   $test_set_params_updates_valid_paramsv  s    r   ztree,datasetr\   )r   random_state)r   c           	      C   sh   t jd}|\}}| || |jddt|d}| ||}| j|||d}d}||ksdJ |d S )Nr   rI   r[   )size)sample_weightz5Unweighted and weighted scores are unexpectedly equal)rF   randomZRandomStaterQ   randintr   score)	treeZdatasetrngrO   rP   r   Zscore_unweightedZscore_weightedr   r#   r#   r$   test_score_sample_weight~  s    r   c                  C   sb   G dd dt t} td}t|}| |dd}t|}|j|jkj sNJ |j	|j	ks^J d S )Nc                   @   s,   e Zd ZdZd
ddZdddZdd	 ZdS )z3test_clone_pandas_dataframe.<locals>.DummyEstimatora,  This is a dummy class for generating numerical features

        This feature extractor extracts numerical features from pandas data
        frame.

        Parameters
        ----------

        df: pandas data frame
            The pandas data frame parameter.

        Notes
        -----
        NrI   c                 S   s   || _ || _d S r   )dfscalar_param)r"   r   r   r#   r#   r$   r%     s    z<test_clone_pandas_dataframe.<locals>.DummyEstimator.__init__c                 S   s   d S r   r#   rN   r#   r#   r$   rQ     s    z7test_clone_pandas_dataframe.<locals>.DummyEstimator.fitc                 S   s   d S r   r#   rR   r#   r#   r$   	transform  s    z=test_clone_pandas_dataframe.<locals>.DummyEstimator.transform)NrI   )N)r'   r(   r)   rE   r%   rQ   r   r#   r#   r#   r$   DummyEstimator  s   

r   r[   rI   )r   )
r   r   rF   Zaranger   r   r   valuesallr   )r   r,   r   eZcloned_er#   r#   r$   test_clone_pandas_dataframe  s    
r   c                  C   s   G dd dt } tddgddgddgg}t |}|j}| |}t|j| t| |  t	ddgddgd	dgg}|| t|j| |
| t|j| t|}||u sJ t|j| d
S )z:Checks that clone works with `__sklearn_clone__` protocol.c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )z,test_clone_protocol.<locals>.FrozenEstimatorc                 S   s
   || _ d S r   )fitted_estimator)r"   r   r#   r#   r$   r%     s    z5test_clone_protocol.<locals>.FrozenEstimator.__init__c                 S   s   t | j|S r   )ry   r   )r"   r{   r#   r#   r$   __getattr__  s    z8test_clone_protocol.<locals>.FrozenEstimator.__getattr__c                 S   s   | S r   r#   rM   r#   r#   r$   __sklearn_clone__  s    z>test_clone_protocol.<locals>.FrozenEstimator.__sklearn_clone__c                 _   s   | S r   r#   r"   argsr   r#   r#   r$   rQ     s    z0test_clone_protocol.<locals>.FrozenEstimator.fitc                 _   s   | j j|i |S r   )r   r   r   r#   r#   r$   fit_transform  s    z:test_clone_protocol.<locals>.FrozenEstimator.fit_transformN)r'   r(   r)   r%   r   r   rQ   r   r#   r#   r#   r$   FrozenEstimator  s
   r   r\   r      rI   N)r   rF   rG   r   rQ   Zcomponents_r   r   Zget_feature_names_outZasarrayr   r   )r   rO   Zpca
componentsZ
frozen_pcaZX_newZclone_frozen_pcar#   r#   r$   test_clone_protocol  s    

r   c                  C   s   t  } t | j| j}t|}d|v s0J t	 $ t
d t|}W d    n1 sb0    Y  || j| j}|| j| j}||ksJ d S )N   _sklearn_versionerror)r   	load_irisr   rQ   rn   targetpickledumpswarningscatch_warningssimplefilterloadsr   )irisr   Ztree_pickleZtree_restoredZscore_of_originalZscore_of_restoredr#   r#   r$   ?test_pickle_version_warning_is_not_raised_with_matching_version  s    


(r   c                   @   s   e Zd Zdd ZdS )TreeBadVersionc                 C   s   t | j ddS )N	something)_sklearn_version)dict__dict__itemsrM   r#   r#   r$   __getstate__  s    zTreeBadVersion.__getstate__Nr'   r(   r)   r   r#   r#   r#   r$   r     s   r   zTrying to unpickle estimator {estimator} from version {old_version} when using version {current_version}. This might lead to breaking code or invalid results. Use at your own risk.c                  C   s   t  } t | j| j}t|}tj	ddt
jd}tjt|d}t| W d    n1 sd0    Y  |jd j}t|tsJ |jdksJ |jdksJ |jt
jksJ d S )Nr   r   r   Zold_versioncurrent_versionr   r   )r   r   r   rQ   rn   r   r   r   pickle_error_messageformatsklearn__version__rf   r   UserWarningr   listmessage
isinstancer   Zestimator_nameZoriginal_sklearn_versionZcurrent_sklearn_version)r   r   Ztree_pickle_otherr   Zwarning_recordr#   r#   r$   <test_pickle_version_warning_is_issued_upon_different_version	  s    
(r   c                   @   s   e Zd Zdd ZdS )TreeNoVersionc                 C   s   | j S r   )r   rM   r#   r#   r$   r     s    zTreeNoVersion.__getstate__Nr   r#   r#   r#   r$   r     s   r   c                  C   s~   t  } t | j| j}t|}d|vs0J tj	ddt
jd}tjt|d t| W d    n1 sp0    Y  d S )Nr   r   zpre-0.18r   r   )r   r   r   rQ   rn   r   r   r   r   r   r   r   rf   r   r   r   )r   r   tree_pickle_noversionr   r#   r#   r$   Dtest_pickle_version_warning_is_issued_when_no_version_info_in_pickle!  s    
r   c                  C   s   t  } t | j| j}t|}zRtj}dt_t	
 $ t	d t| W d    n1 sd0    Y  W |t_n|t_0 d S )N
notsklearnr   )r   r   r   rQ   rn   r   r   r   r(   r   r   r   r   )r   r   r   Zmodule_backupr#   r#   r$   Ctest_pickle_version_no_warning_is_issued_with_non_sklearn_estimator2  s    


*r   c                   @   s   e Zd Zdd Zdd ZdS )DontPickleAttributeMixinc                 C   s   | j  }d |d< |S N_attribute_not_pickled)r   rC   )r"   rn   r#   r#   r$   r   C  s    
z%DontPickleAttributeMixin.__getstate__c                 C   s   d|d< | j | d S )NT	_restored)r   updater"   stater#   r#   r$   __setstate__H  s    z%DontPickleAttributeMixin.__setstate__N)r'   r(   r)   r   r   r#   r#   r#   r$   r   B  s   r   c                   @   s   e Zd ZdddZdS )MultiInheritanceEstimatorr   c                 C   s   || _ d | _d S r   attribute_pickledr   r"   r   r#   r#   r$   r%   N  s    z"MultiInheritanceEstimator.__init__N)r   r&   r#   r#   r#   r$   r   M  s   r   c                  C   sJ   t  } d| _t| }t|}|jdks.J |jd u s<J |jsFJ d S N$this attribute should not be pickledr   )r   r   r   r   r   r   r   r   
serializedZestimator_restoredr#   r#   r$   3test_pickling_when_getstate_is_overwritten_by_mixinS  s    

r   c               	   C   s   zvt  } d}|| _t| j}dt| _|  }|d ddks@J d|d< | | | jdks`J | jsjJ W |t| _n|t| _0 d S )Nr   r   r   )r   r   r   r   )r   r   rx   r(   r   r   r   r   )r   textold_modr   r#   r#   r$   Ftest_pickling_when_getstate_is_overwritten_by_mixin_outside_of_sklearn^  s    


r   c                       s&   e Zd ZdddZ fddZ  ZS )SingleInheritanceEstimatorr   c                 C   s   || _ d | _d S r   r   r   r#   r#   r$   r%   r  s    z#SingleInheritanceEstimator.__init__c                    s   t   }d |d< |S r   )r2   r   r   r8   r#   r$   r   v  s    
z'SingleInheritanceEstimator.__getstate__)r   )r'   r(   r)   r%   r   r;   r#   r#   r8   r$   r   q  s   
r   c                  C   s@   t  } d| _t| }t|}|jdks.J |jd u s<J d S r   )r   r   r   r   r   r   r   r#   r#   r$   Ctest_pickling_works_when_getstate_is_overwritten_in_the_child_class|  s    

r   c                  C   sr   t  } t }|  jjsJ | jjr,J t }| jjrBJ t }| jjsXJ t }| jjsnJ d S r   )r0   r<   r3   r4   r5   r>   r?   rA   )Znan_tag_estZno_nan_tag_estZredefine_tags_estZdiamond_tag_estZinherit_diamond_tag_estr#   r#   r$   test_tag_inheritance  s    r   c                  C   sT   G dd dt } |  }d}tjt|d |  W d    n1 sF0    Y  d S )Nc                   @   s    e Zd ZdddZdddZdS )	z<test_raises_on_get_params_non_attribute.<locals>.MyEstimatorr   c                 S   s   d S r   r#   )r"   paramr#   r#   r$   r%     s    zEtest_raises_on_get_params_non_attribute.<locals>.MyEstimator.__init__Nc                 S   s   | S r   r#   rN   r#   r#   r$   rQ     s    z@test_raises_on_get_params_non_attribute.<locals>.MyEstimator.fit)r   )N)r'   r(   r)   r%   rQ   r#   r#   r#   r$   r     s   
r   z-'MyEstimator' object has no attribute 'param'r   )r   rf   rg   AttributeErrorr^   )r   rj   r   r#   r#   r$   'test_raises_on_get_params_non_attribute  s
    r  c                  C   st   t  } |  }d|v sJ d|v s&J tdd0 |  }d|v sFJ d|vsRJ W d    n1 sf0    Y  d S )Nz
text/plainz	text/htmlr   display)r   _repr_mimebundle_r   )r   outputr#   r#   r$   test_repr_mimebundle_  s    r  c               	   C   s   t  } |  }d|v sJ tddJ d}tjt|d |  }W d    n1 sV0    Y  W d    n1 st0    Y  d S )Nz<style>r   r  z _repr_html_ is only defined whenr   )r   Z_repr_html_r   rf   rg   r  )r   r  r   r#   r#   r$   test_repr_html_wraps  s    r	  c                  C   sv   t  } g dg dg}t| |dd | jdks2J d}tjt|d t| dd	d W d
   n1 sh0    Y  d
S )z>Check that `_check_n_features` validates data when reset=False)rI   r\   r   )r   r      Tresetr   zHX does not contain any features, but MyEstimator is expecting 3 featuresr   	invalid XFN)r   r   n_features_in_rf   rg   r   )rj   ZX_trainr   r#   r#   r$   test_n_features_in_validation  s    r  c                  C   s4   t  } t| ddd t| dr"J t| ddd dS )z]Check that `_check_n_features` does not validate data when
    n_features_in_ is not defined.r  Tr  r  FN)r   r   rd   )rj   r#   r#   r$    test_n_features_in_no_validation  s    r  c               	   C   s  t d} t }|j}| j||jd}G dd dtt}| 	|}t
|j|j |	| t|drlJ |	| d}| j||jddd d}t jt|d	 || W d   n1 s0    Y  d
}t jt|d	 || W d   n1 s0    Y  d}| 	|}t jt|d	 || W d   n1 sH0    Y  | |}| }t & tdt |	| W d   n1 s0    Y  ||g}	|	D ]F}
t & tdt ||
 W d   n1 s0    Y  q| j|g dd}| }td}t jt|d	 |	| W d   n1 sH0    Y  t jt|d	 || W d   n1 s0    Y  dS )z;Check that feature_name_in are recorded by `_validate_data`pandascolumnsc                   @   s   e Zd ZdddZdd ZdS )z.test_feature_names_in.<locals>.NoOpTransformerNc                 S   s   t | | | S r   r   rN   r#   r#   r$   rQ     s    
z2test_feature_names_in.<locals>.NoOpTransformer.fitc                 S   s   t | |dd |S NFr  r  rR   r#   r#   r$   r     s    z8test_feature_names_in.<locals>.NoOpTransformer.transform)Nr'   r(   r)   rQ   r   r#   r#   r#   r$   NoOpTransformer  s   
r  feature_names_in_z5The feature names should match those that were passedNr   r   zVX does not have valid feature names, but NoOpTransformer was fitted with feature nameszIX has feature names, but NoOpTransformer was fitted without feature namesr   )r.   r/   rI   r\   a  Feature names are only supported if all input features have string names, but your input has ['int', 'str'] as feature name / column name types. If you want feature names to be stored and validated, you must convert them all to strings, by using X.columns = X.columns.astype(str) for example. Otherwise you can remove feature / column names from your input data, or convert them all to a non-string data type.)rf   importorskipr   r   rn   	DataFramefeature_namesr   r   rQ   r   r  r  rd   rg   r   r   r   r   r   r   r   reescaperi   )pdr   ZX_npr   r  Ztransr   df_badZdf_int_namesZXsrO   Zdf_mixedr#   r#   r$   test_feature_names_in  sR    



((*

*
.*r   c                  C   s  t d} t }| j|j|jd}| |j}G dd dt	t
}| }t||dd}t|tjsfJ t||  t||dd}||u sJ t||dd}t|tjsJ t||  t||dd}	|	|u sJ t|||dd\}}t|tjsJ t||  t|tjsJ t||  t|||dd\}}	||u sHJ |	|u sVJ d	}
t jt|
d
 t| W d   n1 s0    Y  dS )z0Check skip_check_array option of _validate_data.r  r  c                   @   s   e Zd ZdS )z<test_validate_data_skip_check_array.<locals>.NoOpTransformerNr@   r#   r#   r#   r$   r  0  s   r  F)skip_check_arrayT)rP   r!  z*Validation should be done on X, y or both.r   N)rf   r  r   r   r  rn   r  ZSeriesr   r   r   r   r   rF   Zndarrayr   Zto_numpyrg   r   )r  r   r   rP   r  no_opZX_np_outZX_df_outZy_np_outZy_series_outr   r#   r#   r$   #test_validate_data_skip_check_array(  s6    
r#  c                  C   s:   t  jdd} td| }t| }td|}||ks6J dS )z-Check that clone keeps the set_output config.r  )r   r   N)r   Z
set_outputr   r   )ssconfigZss_cloneZconfig_cloner#   r#   r$   test_clone_keeps_output_configQ  s
    

r&  c                   @   s   e Zd ZdS )_EmptyNr@   r#   r#   r#   r$   r'  \  s   r'  c                   @   s   e Zd ZdS )EmptyEstimatorNr@   r#   r#   r#   r$   r(  `  s   r(  r   c                 C   s4   |   }dtji}||ksJ ttt  dS )zCheck that ``__getstate__`` returns an empty ``dict`` with an empty
    instance.

    Python 3.11+ changed behaviour by returning ``None`` instead of raising an
    ``AttributeError``. Non-regression test for gh-25188.
    r   N)r   r   r   r   r   r   r   )r   r   expectedr#   r#   r$   "test_estimator_empty_instance_dictd  s    
r*  c                  C   s   G dd d} G dd dt | }d}tjt|d |   W d   n1 sR0    Y  tjt|d t|  W d   n1 s0    Y  dS )z:Using a `BaseEstimator` with `__slots__` is not supported.c                   @   s   e Zd ZdZdS )zDtest_estimator_getstate_using_slots_error_message.<locals>.WithSlots)xN)r'   r(   r)   	__slots__r#   r#   r#   r$   	WithSlotsw  s   r-  c                   @   s   e Zd ZdS )zDtest_estimator_getstate_using_slots_error_message.<locals>.EstimatorNr@   r#   r#   r#   r$   	Estimatorz  s   r.  zRYou cannot use `__slots__` in objects inheriting from `sklearn.base.BaseEstimator`r   N)r   rf   rg   ri   r   r   r   )r-  r.  r   r#   r#   r$   1test_estimator_getstate_using_slots_error_messaget  s    (r/  zconstructor_name, minversion))Z	dataframez1.5.0)pyarrowz12.0.0)Zpolarsz0.20.23c           
      C   s   g dg dg}g d}t || ||d}G dd dtt}| }|| t|j| ||}| dkrrt|| g d}t || |d	}	tj	t
d
d ||	 W d   n1 s0    Y  dS )z:Uses the dataframe exchange protocol to get feature names.)rI   r   r\   )r   r   r
  )Zcol_0Zcol_1Zcol_2)columns_name
minversionc                   @   s   e Zd ZdddZdd ZdS )z0test_dataframe_protocol.<locals>.NoOpTransformerNc                 S   s   t | | | S r   r  rN   r#   r#   r$   rQ     s    
z4test_dataframe_protocol.<locals>.NoOpTransformer.fitc                 S   s   t | |ddS r  r  rR   r#   r#   r$   r     s    z:test_dataframe_protocol.<locals>.NoOpTransformer.transform)Nr  r#   r#   r#   r$   r    s   
r  r0  )r.   r/   r+   )r1  zThe feature names should matchr   N)r   r   r   rQ   r   r  r   r   rf   rg   r   )
Zconstructor_namer2  rn   r  r   r  r"  ZX_outZ	bad_namesr  r#   r#   r$   test_dataframe_protocol  s     



r3  )Zenable_metadata_routingc                  C   s   G dd dt t} tjtdd0 |  jddjdggdgdd W d   n1 sV0    Y  tjdd	<}|  jdddggdg t	|d
ksJ W d   n1 s0    Y  dS )zkTest that having a transformer with metadata for transform raises a
    warning when calling fit_transform.c                   @   s    e Zd ZdddZdddZdS )zTtest_transformer_fit_transform_with_metadata_in_transform.<locals>.CustomTransformerNc                 S   s   | S r   r#   r"   rO   rP   propr#   r#   r$   rQ     s    zXtest_transformer_fit_transform_with_metadata_in_transform.<locals>.CustomTransformer.fitc                 S   s   |S r   r#   r"   rO   r5  r#   r#   r$   r     s    z^test_transformer_fit_transform_with_metadata_in_transform.<locals>.CustomTransformer.transform)NN)Nr  r#   r#   r#   r$   CustomTransformer  s   
r7  z*`transform` method which consumes metadatar   Tr5  rI   Nrecordr   )
r   r   rf   r   r   Zset_transform_requestr   r   r   r   )r7  r:  r#   r#   r$   9test_transformer_fit_transform_with_metadata_in_transform  s    	$r;  c                  C   s   G dd dt t} tjtdd0 |  jddjdggdgdd W d   n1 sV0    Y  tjdd	<}|  jdddggdg t	|d
ksJ W d   n1 s0    Y  dS )ziTest that having an OutlierMixin with metadata for predict raises a
    warning when calling fit_predict.c                   @   s    e Zd ZdddZdddZdS )zVtest_outlier_mixin_fit_predict_with_metadata_in_predict.<locals>.CustomOutlierDetectorNc                 S   s   | S r   r#   r4  r#   r#   r$   rQ     s    zZtest_outlier_mixin_fit_predict_with_metadata_in_predict.<locals>.CustomOutlierDetector.fitc                 S   s   |S r   r#   r6  r#   r#   r$   rS     s    z^test_outlier_mixin_fit_predict_with_metadata_in_predict.<locals>.CustomOutlierDetector.predict)NN)N)r'   r(   r)   rQ   rS   r#   r#   r#   r$   CustomOutlierDetector  s   
r<  z(`predict` method which consumes metadatar   Tr8  rI   Nr9  r   )
r   r   rf   r   r   Zset_predict_requestZfit_predictr   r   r   )r<  r:  r#   r#   r$   7test_outlier_mixin_fit_predict_with_metadata_in_predict  s    	$r=  )xr   r  r   numpyrF   rf   Zscipy.sparsesparserm   Znumpy.testingr   r   r   r   Zsklearn.baser   r   r   r   r	   r
   r   r   Zsklearn.clusterr   Zsklearn.decompositionr   Zsklearn.ensembler   Zsklearn.exceptionsr   Zsklearn.model_selectionr   Zsklearn.pipeliner   Zsklearn.preprocessingr   Zsklearn.svmr   r   Zsklearn.treer   r   Zsklearn.utils._mockingr   Zsklearn.utils._set_outputr   Zsklearn.utils._testingr   r   Zsklearn.utils.validationr   r   r   r*   r-   r0   r<   r>   r?   rA   rB   rH   rL   rT   ra   re   rk   rq   rt   rv   r   r   r   r   r   r   r   markZparametrizer   r   r   r   r   r   Zmake_classificationZmake_regressionr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r   r#  r&  r'  r(  r*  r/  r3  r;  r=  r#   r#   r#   r$   <module>   s  (

	  
  
  





&,	
N)

 
