o
    \i                     @   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m	Z	 d dl
Z
d dlZd dlmZ d dlmZmZ d dlmZmZmZmZ d dlmZ d dlmZmZ d dlmZ d d	lm Z m!Z!m"Z" d d
l#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/m0Z0 d dl1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9m:Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA d dlBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZk d dllmmZmmnZn d dlompZp d dlqmrZr d dlsmtZtmuZumvZvmwZw G dd dexZyG dd deeZzG dd deZ{G dd deZ|G d d! d!eZ}G d"d# d#eZ~G d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZG d,d- d-eZG d.d/ d/ezZG d0d1 d1ezZG d2d3 d3ezZG d4d5 d5eZG d6d7 d7ezZG d8d9 d9eZG d:d; d;eZG d<d= d=eZG d>d? d?ezZG d@dA dAeZG dBdC dCeeZG dDdE dEeZG dFdG dGe'ZG dHdI dIeZG dJdK dKe$ZG dLdM dMe$ZG dNdO dOe%ZG dPdQ dQeZG dRdS dSeZdTdU ZdVdW ZdXdY ZdZd[ Zd\d] Zd^d_ Zd`da Zdbdc Zddde Zdfdg Zdhdi Zdjdk Zdldm Zdndo Zdpdq Zdrds Zdtdu Zdvdw Zdxdy Zdzd{ Zd|d} Zd~d Zdd Zdd Zdd Zdd Zdd ZG dd deeZdd Zdd Zdd Zdd Zdd Zdd Zedkre  dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )    N)isgenerator)IntegralReal)config_context
get_config)BaseEstimatorClassifierMixinOutlierMixinTransformerMixin)MiniBatchKMeans)	load_irismake_multilabel_classification)PCA)ConvergenceWarningEstimatorCheckFailedWarningSkipTestWarning)LinearRegressionLogisticRegressionMultiTaskElasticNetSGDClassifier)GaussianMixture)KNeighborsRegressor)StandardScaler)SVCNuSVC)
_array_apiall_estimators
deprecated)Interval
StrOptions)_construct_instances_get_expected_failed_checks)MinimalClassifierMinimalRegressorMinimalTransformerSkipTestignore_warningsraises))_check_name_NotAnArray_yield_all_checkscheck_array_api_input-check_class_weight_balanced_linear_classifier"check_classifier_data_not_an_array*check_classifier_not_supporting_multiclass<check_classifiers_multilabel_output_format_decision_function2check_classifiers_multilabel_output_format_predict8check_classifiers_multilabel_output_format_predict_proba*check_classifiers_one_label_sample_weights(check_dataframe_column_names_consistency check_decision_proba_consistencycheck_dict_unchangedcheck_dont_overwrite_parameterscheck_estimatorcheck_estimator_cloneablecheck_estimator_reprcheck_estimator_sparse_arraycheck_estimator_sparse_matrixcheck_estimator_sparse_tagcheck_estimator_tags_renamedcheck_estimators_nan_inf!check_estimators_overwrite_paramscheck_estimators_unfittedcheck_fit_check_is_fittedcheck_fit_score_takes_y%check_methods_sample_order_invariancecheck_methods_subset_invariancecheck_mixin_ordercheck_no_attributes_set_in_initcheck_outlier_contaminationcheck_outlier_corruption&check_parameters_default_constructible"check_positive_only_tag_during_fit!check_regressor_data_not_an_arraycheck_requires_y_none"check_sample_weights_pandas_seriescheck_set_paramsestimator_checks_generatorset_random_state)CSR_CONTAINERSSPARRAY_PRESENT)available_if)type_of_target)check_arraycheck_is_fitted	check_X_yvalidate_datac                   @   s   e Zd ZdZdS )CorrectNotFittedErrorzException class to raise if estimator is used before fitting.

    Like NotFittedError, it inherits from ValueError, but not from
    AttributeError. Used for testing only.
    N)__name__
__module____qualname____doc__ r^   r^   /var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/lib/python3.10/site-packages/sklearn/utils/tests/test_estimator_checks.pyrY   l   s    rY   c                   @      e Zd Zdd Zdd ZdS )BaseBadClassifierc                 C      | S Nr^   selfXyr^   r^   r_   fitu      zBaseBadClassifier.fitc                 C      t |jd S Nr   nponesshapere   rf   r^   r^   r_   predictx      zBaseBadClassifier.predictNrZ   r[   r\   rh   rq   r^   r^   r^   r_   ra   t       ra   c                   @   s(   e Zd Zd	ddZd
ddZdd ZdS )ChangesDictr   c                 C   
   || _ d S rc   )key)re   rw   r^   r^   r_   __init__}      
zChangesDict.__init__Nc                 C      t | ||\}}| S rc   rX   rd   r^   r^   r_   rh         zChangesDict.fitc                 C   s   t |}d| _t|jd S )Ni  r   )rU   rw   rm   rn   ro   rp   r^   r^   r_   rq      s   zChangesDict.predictr   rc   rZ   r[   r\   rx   rh   rq   r^   r^   r^   r_   ru   |   s    

ru   c                   @       e Zd ZdddZdddZdS )	SetsWrongAttributer   c                 C   rv   rc   )acceptable_key)re   r   r^   r^   r_   rx      ry   zSetsWrongAttribute.__init__Nc                 C      d| _ t| ||\}}| S rk   wrong_attributerX   rd   r^   r^   r_   rh         zSetsWrongAttribute.fitr}   rc   rZ   r[   r\   rx   rh   r^   r^   r^   r_   r          
r   c                   @   r   )	ChangesWrongAttributer   c                 C   rv   rc   )r   )re   r   r^   r^   r_   rx      ry   zChangesWrongAttribute.__init__Nc                 C   r   N   r   rd   r^   r^   r_   rh      r   zChangesWrongAttribute.fitr}   rc   r   r^   r^   r^   r_   r      r   r   c                   @      e Zd ZdddZdS )ChangesUnderscoreAttributeNc                 C   r   r   )_good_attributerX   rd   r^   r^   r_   rh      r   zChangesUnderscoreAttribute.fitrc   rZ   r[   r\   rh   r^   r^   r^   r_   r          r   c                       0   e Zd Zd	ddZ fddZd
ddZ  ZS )RaisesErrorInSetParamsr   c                 C   rv   rc   pre   r   r^   r^   r_   rx      ry   zRaisesErrorInSetParams.__init__c                    s:   d|v r| d}|dk rtd|| _t jdi |S )Nr   r   zp can't be less than 0r^   )pop
ValueErrorr   super
set_paramsre   kwargsr   	__class__r^   r_   r      s   
z!RaisesErrorInSetParams.set_paramsNc                 C   rz   rc   r{   rd   r^   r^   r_   rh      r|   zRaisesErrorInSetParams.fitr}   rc   rZ   r[   r\   rx   r   rh   __classcell__r^   r^   r   r_   r          
r   c                   @   s$   e Zd Ze fddZdddZdS )HasMutableParametersc                 C   rv   rc   r   r   r^   r^   r_   rx      ry   zHasMutableParameters.__init__Nc                 C   rz   rc   r{   rd   r^   r^   r_   rh      r|   zHasMutableParameters.fitrc   )rZ   r[   r\   objectrx   rh   r^   r^   r^   r_   r      s    r   c                   @   s,   e Zd ZdedefddZdddZdS )HasImmutableParameters*   c                 C      || _ || _|| _d S rc   )r   qr)re   r   r   r   r^   r^   r_   rx         
zHasImmutableParameters.__init__Nc                 C   rz   rc   r{   rd   r^   r^   r_   rh      r|   zHasImmutableParameters.fitrc   )rZ   r[   r\   rm   int32r   rx   rh   r^   r^   r^   r_   r      s    r   c                       r   )"ModifiesValueInsteadOfRaisingErrorr   c                 C   rv   rc   r   r   r^   r^   r_   rx      ry   z+ModifiesValueInsteadOfRaisingError.__init__c                    s6   d|v r| d}|dk rd}|| _t jdi |S )Nr   r   r^   )r   r   r   r   r   r   r^   r_   r      s   
z-ModifiesValueInsteadOfRaisingError.set_paramsNc                 C   rz   rc   r{   rd   r^   r^   r_   rh      r|   z&ModifiesValueInsteadOfRaisingError.fitr}   rc   r   r^   r^   r   r_   r      r   r   c                       s0   e Zd Zd
ddZ fddZddd	Z  ZS )ModifiesAnotherValuer   method1c                 C   s   || _ || _d S rc   )ab)re   r   r   r^   r^   r_   rx      s   
zModifiesAnotherValue.__init__c                    sB   d|v r| d}|| _|d u r| d d| _t jdi |S )Nr   r   method2r^   )r   r   r   r   r   )re   r   r   r   r^   r_   r      s   

zModifiesAnotherValue.set_paramsNc                 C   rz   rc   r{   rd   r^   r^   r_   rh      r|   zModifiesAnotherValue.fit)r   r   rc   r   r^   r^   r   r_   r      s    
	r   c                   @      e Zd Zdd ZdS )NoCheckinPredictc                 C   rz   rc   r{   rd   r^   r^   r_   rh      r|   zNoCheckinPredict.fitNr   r^   r^   r^   r_   r          r   c                   @   s&   e Zd ZdddZdd Zdd ZdS )	NoSparseClassifierNc                 C   rv   rc   raise_for_typere   r   r^   r^   r_   rx         
zNoSparseClassifier.__init__c                 C   sV   t | ||ddgd\}}| jdkrt|tj}n| jdkr#t|tj}|r)td| S )Ncsrcscaccept_sparsesparse_arraysparse_matrixNonsensical Error)rX   r   
isinstancespsparrayspmatrixr   re   rf   rg   correct_typer^   r^   r_   rh      s   

zNoSparseClassifier.fitc                 C      t |}t|jd S rk   rU   rm   rn   ro   rp   r^   r^   r_   rq        zNoSparseClassifier.predictrc   r~   r^   r^   r^   r_   r      s    

r   c                   @   r`   )CorrectNotFittedErrorClassifierc                 C   s&   t | ||\}}t|jd | _| S r   )rX   rm   rn   ro   coef_rd   r^   r^   r_   rh   
  s   z#CorrectNotFittedErrorClassifier.fitc                 C   s    t |  t|}t|jd S rk   )rV   rU   rm   rn   ro   rp   r^   r^   r_   rq     s   z'CorrectNotFittedErrorClassifier.predictNrs   r^   r^   r^   r_   r   	  s    r   c                   @      e Zd ZdddZdd ZdS )NoSampleWeightPandasSeriesTypeNc                 C   s:   t | ||dddd\}}ddlm} t||rtd| S )Nr   r   Tr   multi_output	y_numericr   Seriesz>Estimator does not accept 'sample_weight'of type pandas.Series)rX   pandasr   r   r   )re   rf   rg   sample_weightr   r^   r^   r_   rh     s   

z"NoSampleWeightPandasSeriesType.fitc                 C   r   rk   r   rp   r^   r^   r_   rq   $  r   z&NoSampleWeightPandasSeriesType.predictrc   rs   r^   r^   r^   r_   r     s    
r   c                   @   r   )BadBalancedWeightsClassifierNc                 C   rv   rc   )class_weight)re   r   r^   r^   r_   rx   *  ry   z%BadBalancedWeightsClassifier.__init__c                 C   sV   ddl m} ddlm} | |}|j}|| j||d}| jdkr&|d7 }|| _| S )Nr   )LabelEncoder)compute_class_weight)classesrg   balanced      ?)sklearn.preprocessingr   sklearn.utilsr   rh   classes_r   r   )re   rf   rg   r   r   label_encoderr   r   r^   r^   r_   rh   -  s   
z BadBalancedWeightsClassifier.fitrc   r   r^   r^   r^   r_   r   )  s    
r   c                   @   r   )BadTransformerWithoutMixinNc                 C   s   t | |}| S rc   r{   rd   r^   r^   r_   rh   @     
zBadTransformerWithoutMixin.fitc                 C   s   t |  t| |dd}|S )NFreset)rV   rX   rp   r^   r^   r_   	transformD  s   z$BadTransformerWithoutMixin.transformrc   )rZ   r[   r\   rh   r   r^   r^   r^   r_   r   ?  s    
r   c                   @   r`   )NotInvariantPredictc                 C   s   t | ||dddd\}}| S Nr   Tr   r{   rd   r^   r^   r_   rh   K  s   
zNotInvariantPredict.fitc                 C   s6   t |}|jd dkrt|jd S t|jd S )Nr   r   )rU   ro   rm   rn   zerosrp   r^   r^   r_   rq   R  s   zNotInvariantPredict.predictNrs   r^   r^   r^   r_   r   J  s    r   c                   @   r`   )NotInvariantSampleOrderc                 C   s"   t | ||dddd\}}|| _| S r   )rX   _Xrd   r^   r^   r_   rh   [  s
   
zNotInvariantSampleOrder.fitc                 C   sX   t |}ttj|ddtj| jddr$|| jk r$t|jd S |d d df S )Nr   )axis)rU   rm   array_equivsortr   anyr   ro   rp   r^   r^   r_   rq   c  s    zNotInvariantSampleOrder.predictNrs   r^   r^   r^   r_   r   Z  s    r   c                   @   s,   e Zd ZdZd
ddZdddZdd	 ZdS )OneClassSampleErrorClassifierzoClassifier allowing to trigger different behaviors when `sample_weight` reduces
    the number of classes to 1.Fc                 C   rv   rc   )raise_when_single_class)re   r   r^   r^   r_   rx   s  ry   z&OneClassSampleErrorClassifier.__init__Nc                 C   s   t ||dddd\}}d| _tj|dd\| _}| jjd }|dk r,| jr,d| _td|d urPt|tj	rEt
|dkrEtt||}|dk rPd| _td	| S )
Nr   Tr   F)return_inverser      znormal class errorr   )rW   has_single_class_rm   uniquer   ro   r   r   r   ndarraylencount_nonzerobincount)re   rf   rg   r   
n_classes_r^   r^   r_   rh   v  s    

z!OneClassSampleErrorClassifier.fitc                 C   s6   t |  t|}| jrt|jd S t|jd S rk   )rV   rU   r   rm   r   ro   rn   rp   r^   r^   r_   rq     s
   z%OneClassSampleErrorClassifier.predict)Frc   rZ   r[   r\   r]   rx   rh   rq   r^   r^   r^   r_   r   o  s
    

r   c                   @   s"   e Zd ZdZdddZdd ZdS )!LargeSparseNotSupportedClassifierz^Estimator that claims to support large sparse data
    (accept_large_sparse=True), but doesn'tNc                 C   rv   rc   r   r   r^   r^   r_   rx     r   z*LargeSparseNotSupportedClassifier.__init__c              	   C   s   t | ||ddddd\}}| jdkrt|tj}n| jdkr$t|tj}|rP|jdkr=|jjdks7|j	jdkr;t
d| S |jd	v rPd|jj|jjfvsPJ d| S )
N)r   r   cooT)r   accept_large_sparser   r   r   r   r   int64z(Estimator doesn't support 64-bit indices)r   r   )rX   r   r   r   r   r   formatrowdtypecolr   indicesindptrr   r^   r^   r_   rh     s4   

	


z%LargeSparseNotSupportedClassifier.fitrc   )rZ   r[   r\   r]   rx   rh   r^   r^   r^   r_   r     s    
r   c                   @   s2   e Zd Zd
ddZd
ddZd
ddZdd	 ZdS )SparseTransformerNc                 C   rv   rc   sparse_container)re   r  r^   r^   r_   rx     ry   zSparseTransformer.__init__c                 C   s   t | | | S rc   r{   rd   r^   r^   r_   rh     r   zSparseTransformer.fitc                 C   s   |  |||S rc   )rh   r   rd   r^   r^   r_   fit_transform     zSparseTransformer.fit_transformc                 C   s"   t |  t| |ddd}| |S )NTF)r   r   )rV   rX   r  rp   r^   r^   r_   r     s   
zSparseTransformer.transformrc   )rZ   r[   r\   rx   rh   r  r   r^   r^   r^   r_   r    s
    


r  c                   @   r`   )EstimatorInconsistentForPandasc                 C   sj   z ddl m} t||r|jd | _| W S t|}|d | _| W S  ty4   t|}|d | _|  Y S w )Nr   )	DataFrame)r   r   )r   r   )r   r  r   ilocvalue_rU   ImportError)re   rf   rg   r  r^   r^   r_   rh     s   


z"EstimatorInconsistentForPandas.fitc                 C   s    t |}t| jg|jd  S rk   )rU   rm   arrayr
  ro   rp   r^   r^   r_   rq     s   z&EstimatorInconsistentForPandas.predictNrs   r^   r^   r^   r_   r    s    r  c                       s,   e Zd Zd fdd	Zd fdd	Z  ZS )UntaggedBinaryClassifierNc                    s.   t  ||||| t| jdkrtd| S )Nr   Only 2 classes are supported)r   rh   r   r   r   )re   rf   rg   	coef_initintercept_initr   r   r^   r_   rh        zUntaggedBinaryClassifier.fitc                    s.   t  j||||d t| jdkrtd| S )N)rf   rg   r   r   r   r  )r   partial_fitr   r   r   )re   rf   rg   r   r   r   r^   r_   r    r  z$UntaggedBinaryClassifier.partial_fit)NNNNN)rZ   r[   r\   rh   r  r   r^   r^   r   r_   r    s    r  c                       (   e Zd Z fddZ fddZ  ZS )TaggedBinaryClassifierc                    s4   t |ddd}|dkrtd| dt ||S )Nrg   T)
input_nameraise_unknownbinaryzCOnly binary classification is supported. The type of the target is .)rT   r   r   rh   )re   rf   rg   y_typer   r^   r_   rh     s   zTaggedBinaryClassifier.fitc                       t   }d|j_|S NF)r   __sklearn_tags__classifier_tagsmulti_classre   tagsr   r^   r_   r       
z'TaggedBinaryClassifier.__sklearn_tags__rZ   r[   r\   rh   r  r   r^   r^   r   r_   r    s    
r  c                       r  )RequiresPositiveXRegressorc                    s8   t | ||ddd\}}|dk  rtdt ||S )NFTr   r   r   z$Negative values in data passed to X.rX   r   r   r   rh   rd   r   r^   r_   rh     s   zRequiresPositiveXRegressor.fitc                    s   t   }d|j_d|j_|S )NTF)r   r  
input_tagspositive_onlysparser   r   r^   r_   r    s   
z+RequiresPositiveXRegressor.__sklearn_tags__r#  r^   r^   r   r_   r$    s    r$  c                       r  )RequiresPositiveYRegressorc                    s8   t | ||ddd\}}|dk rtdt ||S )NTr%  r    negative y values not supported!r&  rd   r   r^   r_   rh     s   zRequiresPositiveYRegressor.fitc                    r  NT)r   r  target_tagsr(  r   r   r^   r_   r    r"  z+RequiresPositiveYRegressor.__sklearn_tags__r#  r^   r^   r   r_   r*    s    r*  c                       r  )PoorScoreLogisticRegressionc                    s   t  |d S r   )r   decision_functionrp   r   r^   r_   r/    rr   z-PoorScoreLogisticRegression.decision_functionc                    r  r,  )r   r  r  
poor_scorer   r   r^   r_   r    r"  z,PoorScoreLogisticRegression.__sklearn_tags__)rZ   r[   r\   r/  r  r   r^   r^   r   r_   r.    s    r.  c                   @   r`   )PartialFitChecksNamec                 C   s   t | || | S rc   r{   rd   r^   r^   r_   rh   &  s   zPartialFitChecksName.fitc                 C   s&   t | d }t| |||d d| _| S )N_fittedr   T)hasattrrX   r2  )re   rf   rg   r   r^   r^   r_   r  *  s   z PartialFitChecksName.partial_fitN)rZ   r[   r\   rh   r  r^   r^   r^   r_   r1  %  s    r1  c                   @   s    e Zd ZdZdd Zdd ZdS )BrokenArrayAPIz=Make different predictions when using Numpy and the Array APIc                 C   rb   rc   r^   rd   r^   r^   r_   rh   4  ri   zBrokenArrayAPI.fitc                 C   s8   t  d }t|\}}|r|g dS tg dS )Narray_api_dispatch)r   r      )r6  r   r   )r   r   get_namespaceasarrayrm   r  )re   rf   enabledxp_r^   r^   r_   rq   7  s
   
zBrokenArrayAPI.predictN)rZ   r[   r\   r]   rh   rq   r^   r^   r^   r_   r4  1  s    r4  c                   C   sj   zt d W n ty   tdw ttdd tdt ddd W d    d S 1 s.w   Y  d S )Narray_api_strictz-array-api-strict is required to run this testNot equal to tolerancematchr4  T)array_namespacecheck_values)	importlibimport_moduleModuleNotFoundErrorr%   r'   AssertionErrorr+   r4  r^   r^   r^   r_   test_check_array_api_input@  s   "rF  c                  C   s\   t td} d}tt|d t|  W d    n1 sw   Y  t| d s,J d S )N
   z&Don't want to call array_function sum!r>  )r)   rm   rn   r'   	TypeErrorsummay_share_memory)	not_arraymsgr^   r^   r_    test_not_an_array_array_functionO  s   rM  c                  C   s    G dd dt } td|   d S )Nc                   @   s   e Zd Zeddd ZdS )zbtest_check_fit_score_takes_y_works_on_deprecated_fit.<locals>.TestEstimatorWithDeprecatedFitMethodz=Deprecated for the purpose of testing check_fit_score_takes_yc                 S   rb   rc   r^   rd   r^   r^   r_   rh   ]  s   zftest_check_fit_score_takes_y_works_on_deprecated_fit.<locals>.TestEstimatorWithDeprecatedFitMethod.fitN)rZ   r[   r\   r   rh   r^   r^   r^   r_   $TestEstimatorWithDeprecatedFitMethod\  s    rN  test)r   rB   )rN  r^   r^   r_   4test_check_fit_score_takes_y_works_on_deprecated_fitX  s   rP  c                  C   s>   d} t t| d tt W d   dS 1 sw   Y  dS )z7Test that passing a class instead of an instance fails.zPassing a class was deprecatedr>  N)r'   rH  r7   r   rL  r^   r^   r_   'test_check_estimator_with_class_removedd  s   
"rR  c                  C   sN   d} t dt  tt| d t dt  W d   dS 1 s w   Y  dS )z=Test that constructor cannot have mutable default parameters.zXParameter 'p' of estimator 'HasMutableParameters' is of type object which is not allowed	Immutabler>  MutableN)rI   r   r'   rE  r   rQ  r^   r^   r_   test_mutable_default_paramsk  s   "rU  c                  C   s   d} t t| d tdt  W d   n1 sw   Y  tjdd}tdt  W d   n1 s5w   Y  tdd |D v sEJ t t| d tdt  W d   dS 1 s]w   Y  dS )	z8Check set_params doesn't fail and sets the right values.z>get_params result does not match what was passed to set_paramsr>  rO  NTrecordc                 S      g | ]}|j qS r^   category.0recr^   r^   r_   
<listcomp>      z)test_check_set_params.<locals>.<listcomp>)	r'   rE  rN   r   warningscatch_warningsr   UserWarningr   )rL  recordsr^   r^   r_   test_check_set_paramsy  s   "rd  c                  C   B   d} t t| d tdt  W d    d S 1 sw   Y  d S )NzCEstimator NoCheckinPredict doesn't check for NaN and inf in predictr>  r   )r'   rE  r>   r   rQ  r^   r^   r_   test_check_estimators_nan_inf  s   "rf  c                  C   re  )Nz)Estimator changes __dict__ during predictr>  rO  )r'   rE  r5   ru   rQ  r^   r^   r_   test_check_dict_unchanged  s   "rg  c                  C   sh   z)ddl m}  d}tt|d tdt  W d    W d S 1 s"w   Y  W d S  ty3   Y d S w )Nr   r   zkEstimator NoSampleWeightPandasSeriesType raises error if 'sample_weight' parameter is of type pandas.Seriesr>  r   )r   r   r'   r   rM   r   r  )r   rL  r^   r^   r_   'test_check_sample_weights_pandas_series  s   &rh  c                  C   sL   d} t t| d tdt  W d    n1 sw   Y  tdt  d S )NzrEstimator ChangesWrongAttribute should not change or mutate  the parameter wrong_attribute from 0 to 1 during fit.r>  r   rO  )r'   rE  r?   r   r   rQ  r^   r^   r_   &test_check_estimators_overwrite_params  s   ri  c                  C   re  )NzEstimator adds public attribute\(s\) during the fit method. Estimators are only allowed to add private attributes either started with _ or ended with _ but wrong_attribute addedr>  rO  )r'   rE  r6   r   rQ  r^   r^   r_   $test_check_dont_overwrite_parameters  s
   "rj  c                  C   V   t j} d}dj|| d}tt|d tdt   W d    d S 1 s$w   Y  d S )Nrq   zY{method} of {name} is not invariant when applied to a datasetwith different sample order.methodnamer>  r   )r   rZ   r   r'   rE  rC   rn  rm  rL  r^   r^   r_   *test_check_methods_sample_order_invariance  s   "rp  c                  C   rk  )Nrq   z={method} of {name} is not invariant when applied to a subset.rl  r>  r   )r   rZ   r   r'   rE  rD   ro  r^   r^   r_   $test_check_methods_subset_invariance  s   "rq  c                  C   s  t j} d|  }tt|d t| t d W d    n1 sw   Y  trCtt|d t| t d W d    n1 s>w   Y  d}tt|d tdtd W d    n1 s]w   Y  trtt|d tdtd W d    d S 1 s}w   Y  d S d S )Nz;Estimator %s doesn't seem to fail gracefully on sparse datar>  r   r   ztEstimator LargeSparseNotSupportedClassifier doesn't seem to support \S{3}_64 matrix, and is not failing gracefully.*r   )r   rZ   r'   rE  r;   rR   r:   r   rn  rL  r^   r^   r_    test_check_estimator_sparse_data  s2   "rs  c                  C   sN   t j} |  d}tt|d tdt   W d    d S 1 s w   Y  d S )Nzu failed when fitted on one label after sample_weight trimming. Error message is not explicit, it should have 'class'.r>  r   )r   rZ   r'   rE  r2   rr  r^   r^   r_   /test_check_classifiers_one_label_sample_weights  s   "rt  c                  C   sr   t t dd} t| tsJ t| dksJ tdd | D s!J tdd | D s,J tdd | D s7J dS )zCheck the contents of the results returned with on_fail!="raise".

    This results should contain details about the observed failures, expected
    or not.
    N)on_failr   c                 s   s.    | ]}t |tot| h d kV  qdS )>   status	estimator	exception
check_nameexpected_to_failexpected_to_fail_reasonN)r   dictsetkeysr\  itemr^   r^   r_   	<genexpr>  s    


z5test_check_estimator_not_fail_fast.<locals>.<genexpr>c                 s       | ]	}|d  dkV  qdS )rv  failedNr^   r  r^   r^   r_   r        c                 s   r  )rv  passedNr^   r  r^   r^   r_   r    r  )r7   r   r   listr   allr   )check_resultsr^   r^   r_   "test_check_estimator_not_fail_fast  s   r  c                  C   s
  d} t t| d tt  W d    n1 sw   Y  d} t t| d tt  W d    n1 s5w   Y  tD ]	}tt|d q<tt  ttdd tt	  tt
  tt  d} t t| d tt  W d    n1 syw   Y  tt  d S )Nzobject has no attribute 'fit'r>  r  r  g{Gz?)Cr+  )r'   AttributeErrorr7   r   r   r  rQ   r  r   r   r  r$  r*  r.  )rL  csr_containerr^   r^   r_   test_check_estimator"  s(   



r  c                  C   s`   t g d} tt tdd|  W d    n1 sw   Y  t g d} tdd|  d S )N)        r   g      ?       @r   r   )r  r   r   r  )rm   r  r'   rE  rH   )decisionr^   r^   r_   test_check_outlier_corruptionF  s   
r  c               	   C   s
  G dd dt } ddddddddddtdddtdg}|D ]6}| |d |d }|d	 du r9t|jj| q t|d	  t|jj| W d   n1 sQw   Y  q td
tdfD ]#}| dd|}tt t|jj| W d   n1 s}w   Y  q_dS )zTTest that check_estimator_sparse_tag raises error when sparse tag is
    misaligned.c                       s0   e Zd ZdddZdddZ fddZ  ZS )	zBtest_check_estimator_sparse_tag.<locals>.EstimatorWithSparseConfigNc                 S   r   rc   )
tag_sparser   	fit_error)re   r  r   r  r^   r^   r_   rx   U  r   zKtest_check_estimator_sparse_tag.<locals>.EstimatorWithSparseConfig.__init__c                 S   s"   | j r| j t| ||| jd | S )Nr   )r  rX   r   rd   r^   r^   r_   rh   Z  s   zFtest_check_estimator_sparse_tag.<locals>.EstimatorWithSparseConfig.fitc                    s   t   }| j|j_|S rc   )r   r  r  r'  r)  r   r   r^   r_   r  `  s   

zStest_check_estimator_sparse_tag.<locals>.EstimatorWithSparseConfig.__sklearn_tags__rc   rZ   r[   r\   rx   rh   r  r   r^   r^   r   r_   EstimatorWithSparseConfigT  s    

r  TN)r  r   
error_typeFr  r   r  zunexpected errorzother error)r   rE  r<   r   rZ   r'   rH  KeyError)r  
test_cases	test_caserw  r  r^   r^   r_   test_check_estimator_sparse_tagP  s0   




r  c                   C   s:   t td tt  W d    d S 1 sw   Y  d S )Nz%the `transformer_tags` tag is not set)r'   RuntimeErrorr7   r   r^   r^   r^   r_   )test_check_estimator_transformer_no_mixin  s   "r  c               	   C   s   t  } tttttfD ]n}ttd | }t| t	
|}t|t|d W d    n1 s0w   Y  |t	
|ks>J ttd$ | }t| || j| j t	
|}t|t|d W d    n1 sjw   Y  |t	
|ksxJ q
d S )NrY  expected_failed_checks)r   r   r   r   r   r   r&   r   rP   joblibhashr7   r!   rh   datatarget)iris	Estimatorestold_hashr^   r^   r_   test_check_estimator_clones  s6   

r  c                  C   sL   d} t t| d tdt  W d    n1 sw   Y  tdt  d S )Nz4Estimator should raise a NotFittedError when callingr>  rw  )r'   rE  r@   r   r   rQ  r^   r^   r_   test_check_estimators_unfitted  s
   r  c                  C   s   G dd dt } G dd dt }G dd dt }d}tt|d td	|   W d    n1 s1w   Y  d
}tt|d td	|  W d    n1 sOw   Y  td	|  tdd td	| jdd W d    d S 1 suw   Y  d S )Nc                   @   r   )zNtest_check_no_attributes_set_in_init.<locals>.NonConformantEstimatorPrivateSetc                 S   s
   d | _ d S rc   )you_should_not_set_this_re   r^   r^   r_   rx     ry   zWtest_check_no_attributes_set_in_init.<locals>.NonConformantEstimatorPrivateSet.__init__NrZ   r[   r\   rx   r^   r^   r^   r_    NonConformantEstimatorPrivateSet  r   r  c                   @   r   )zNtest_check_no_attributes_set_in_init.<locals>.NonConformantEstimatorNoParamSetNc                 S      d S rc   r^   )re   you_should_set_this_r^   r^   r_   rx     ri   zWtest_check_no_attributes_set_in_init.<locals>.NonConformantEstimatorNoParamSet.__init__rc   r  r^   r^   r^   r_    NonConformantEstimatorNoParamSet  r   r  c                   @   s   e Zd ZddiZdS )zOtest_check_no_attributes_set_in_init.<locals>.ConformantEstimatorClassAttributefooTN)rZ   r[   r\   9_ConformantEstimatorClassAttribute__metadata_request__fitr^   r^   r^   r_   !ConformantEstimatorClassAttribute  s    r  zEstimator estimator_name should not set any attribute apart from parameters during init. Found attributes \['you_should_not_set_this_'\].r>  estimator_namezPEstimator estimator_name should store all parameters as an attribute during initT)enable_metadata_routing)r  )r   r'   rE  rF   r  r   set_fit_request)r  r  r  rL  r^   r^   r_   $test_check_no_attributes_set_in_init  s4   "r  c                  C   s0   t dd} t|  tdd} t| t| d d S )Nprecomputed)kernel)metricr  )r   r7   r   r!   )r  r^   r^   r_   test_check_estimator_pairwise  s   

r  c                   C   >   t tdd tdt  W d    d S 1 sw   Y  d S Nr=  r>  r  )r'   rE  r-   r  r^   r^   r^   r_   'test_check_classifier_data_not_an_array  
   "r  c                   C   r  r  )r'   rE  rK   r  r^   r^   r^   r_   &test_check_regressor_data_not_an_array  r  r  c                  C   s   d} t t| d tdt  W d    n1 sw   Y  tdt  t }t|jj| d|_d} t t| d t|jj| W d    d S 1 sLw   Y  d S )Nz+Estimator does not have a feature_names_in_r>  r  z;Docstring that does not document the estimator's attributeszNEstimator LogisticRegression does not document its feature_names_in_ attribute)	r'   r   r3   ra   r1  r   r   rZ   r]   )err_msglrr^   r^   r_   -test_check_dataframe_column_names_consistency  s   "r  c                       s,   e Zd Zdd Zdd Z fddZ  ZS )_BaseMultiLabelClassifierMockc                 C   rv   rc   response_output)re   r  r^   r^   r_   rx     ry   z&_BaseMultiLabelClassifierMock.__init__c                 C   rb   rc   r^   rd   r^   r^   r_   rh     ri   z!_BaseMultiLabelClassifierMock.fitc                    r  r,  )r   r  r  multi_labelr   r   r^   r_   r    r"  z._BaseMultiLabelClassifierMock.__sklearn_tags__r  r^   r^   r   r_   r    s    r  c            	   	   C   s<  d\} }}t | d|ddddd\}}|| d  }G dd	 d	t}|| d
}d}tt|d t|jj| W d    n1 sBw   Y  ||d d d df d
}d}tt|d t|jj| W d    n1 snw   Y  ||t	j
d
}d}tt|d t|jj| W d    d S 1 sw   Y  d S )Nd         r   r6  2   Tr   	n_samples
n_features	n_classesn_labelslengthallow_unlabeledrandom_statec                   @   r   )z\test_check_classifiers_multilabel_output_format_predict.<locals>.MultiLabelClassifierPredictc                 S      | j S rc   r  rp   r^   r^   r_   rq   (     zdtest_check_classifiers_multilabel_output_format_predict.<locals>.MultiLabelClassifierPredict.predictN)rZ   r[   r\   rq   r^   r^   r^   r_   MultiLabelClassifierPredict'  r   r  r  zdMultiLabelClassifierPredict.predict is expected to output a NumPy array. Got <class 'list'> instead.r>  zbMultiLabelClassifierPredict.predict outputs a NumPy array of shape \(25, 4\) instead of \(25, 5\).zTMultiLabelClassifierPredict.predict does not output the same dtype than the targets.)r   r  tolistr'   rE  r0   r   rZ   astyperm   float64)	r  	test_size	n_outputsr;  rg   y_testr  clfr  r^   r^   r_   7test_check_classifiers_multilabel_output_format_predict  s<   

	"r  c            
   	      s   d\} }}t | d|ddddd\}}|| d   G dd	 d	t}tD ]-}|| d
}d|j d}tt|d t|jj| W d    n1 sKw   Y  q#|  d
}d| d| d}tt	|d t|jj| W d    n1 syw   Y   fddt
|D }	||	d
}d}tt	|d t|jj| W d    n1 sw   Y   fddt
|D }	||	d
}d}tt	|d t|jj| W d    n1 sw   Y   fddt
|D }	||	d
}d}tt	|d t|jj| W d    n	1 sw   Y  | d d d df d
}d}tt	|d t|jj| W d    n	1 s4w   Y  tj tjd}	||	d
}d}tt	|d t|jj| W d    n	1 saw   Y  | d d
}d}tt	|d t|jj| W d    d S 1 sw   Y  d S )Nr  r   r6  r  Tr   r  c                   @   r   )zgtest_check_classifiers_multilabel_output_format_predict_proba.<locals>.MultiLabelClassifierPredictProbac                 S   r  rc   r  rp   r^   r^   r_   predict_probaS  r  zutest_check_classifiers_multilabel_output_format_predict_proba.<locals>.MultiLabelClassifierPredictProba.predict_probaN)rZ   r[   r\   r  r^   r^   r^   r_    MultiLabelClassifierPredictProbaR  r   r  r  zUnknown returned type .*zZ.* by MultiLabelClassifierPredictProba.predict_proba. A list or a Numpy array is expected.r>  zWhen MultiLabelClassifierPredictProba.predict_proba returns a list, the list should be of length n_outputs and contain NumPy arrays. Got length of z instead of r  c                    s   g | ]}t  qS r^   )rm   	ones_liker\  r;  r  r^   r_   r^  q      zQtest_check_classifiers_multilabel_output_format_predict_proba.<locals>.<listcomp>zWhen MultiLabelClassifierPredictProba.predict_proba returns a list, this list should contain NumPy arrays of shape \(n_samples, 2\). Got NumPy arrays of shape \(25, 5\) instead of \(25, 2\).c                    &   g | ]}t j jd  dft jdqS r   r   )ro   r   )rm   rn   ro   r   r  r  r^   r_   r^  ~      zwWhen MultiLabelClassifierPredictProba.predict_proba returns a list, it should contain NumPy arrays with floating dtype.c                    r  r  )rm   rn   ro   r  r  r  r^   r_   r^    r  zWhen MultiLabelClassifierPredictProba.predict_proba returns a list, each NumPy array should contain probabilities for each class and thus each row should sum to 1r  zWhen MultiLabelClassifierPredictProba.predict_proba returns a NumPy array, the expected shape is \(n_samples, n_outputs\). Got \(25, 4\) instead of \(25, 5\).)r   znWhen MultiLabelClassifierPredictProba.predict_proba returns a NumPy array, the expected data type is floating.r  zWhen MultiLabelClassifierPredictProba.predict_proba returns a NumPy array, this array is expected to provide probabilities of the positive class and should therefore contain values between 0 and 1.)r   r  rQ   rZ   r'   r   r1   r   r  rE  rangerm   
zeros_liker   )
r  r  r  r;  rg   r  r  r  r  r  r^   r  r_   =test_check_classifiers_multilabel_output_format_predict_probaE  s   

	





$r  c            	   	   C   s4  d\} }}t | d|ddddd\}}|| d  }G dd	 d	t}|| d
}d}tt|d t|jj| W d    n1 sBw   Y  ||d d d df d
}d}tt|d t|jj| W d    n1 snw   Y  ||d
}d}tt|d t|jj| W d    d S 1 sw   Y  d S )Nr  r   r6  r  Tr   r  c                   @   r   )zotest_check_classifiers_multilabel_output_format_decision_function.<locals>.MultiLabelClassifierDecisionFunctionc                 S   r  rc   r  rp   r^   r^   r_   r/    r  ztest_check_classifiers_multilabel_output_format_decision_function.<locals>.MultiLabelClassifierDecisionFunction.decision_functionN)rZ   r[   r\   r/  r^   r^   r^   r_   $MultiLabelClassifierDecisionFunction  r   r  r  zwMultiLabelClassifierDecisionFunction.decision_function is expected to output a NumPy array. Got <class 'list'> instead.r>  r  zMultiLabelClassifierDecisionFunction.decision_function is expected to provide a NumPy array of shape \(n_samples, n_outputs\). Got \(25, 4\) instead of \(25, 5\)z^MultiLabelClassifierDecisionFunction.decision_function is expected to output a floating dtype.)r   r  r  r'   rE  r/   r   rZ   )	r  r  r  r;  rg   r  r  r  r  r^   r^   r_   Atest_check_classifiers_multilabel_output_format_decision_function  sN   

	
"r  c                     sV   t jd   fddt D } dd | D }t }|| t }|| dS )z1Runs the tests in this file without using pytest.__main__c                    s    g | ]}| d rt |qS )test_)
startswithgetattr)r\  rn  main_moduler^   r_   r^    s    z,run_tests_without_pytest.<locals>.<listcomp>c                 S   s   g | ]}t |qS r^   )unittestFunctionTestCase)r\  fnr^   r^   r_   r^    r  N)sysmodulesdirr  	TestSuiteaddTestsTextTestRunnerrun)test_functionsr  suiterunnerr^   r  r_   run_tests_without_pytest  s   


r  c                  C   re  )NzIClassifier estimator_name is not computing class_weight=balanced properlyr>  r  )r'   rE  r,   r   rQ  r^   r^   r_   2test_check_class_weight_balanced_linear_classifier  s   "r  c                  C   sZ   t jdd} t }W d    n1 sw   Y  | rJ |D ]}|jjdr*J qd S )NTrV  r;  )r`  ra  r   r   rZ   r  )rW  
estimatorsr  r^   r^   r_   test_all_estimators_all_public  s   r  r  c               	   C   s   t tt} t| }t| d|dd}t|dksJ g }|D ]\}}z|| W q ty8   |t| Y qw t	|
 t	|ksEJ d S )NTskip)legacyr  markr   )nextr    r   r!   rO   r   r%   appendr(   r}  r~  )r  rz  checksskipped_checksrw  checkr^   r^   r_   .test_estimator_checks_generator_skipping_tests  s   r  c                  C   s   t  } t| }t|dksJ tjdd}t| |dd}W d   n1 s'w   Y  dd |D }td	d |D s>J t|t|ksHJ d
d |D }t|t|ksYJ dS )zTest that the right number of xfail warnings are raised when on_fail is "warn".

    It also checks the number of raised EstimatorCheckFailedWarning, and checks the
    output of check_estimator.
    r   TrV  warn)r  ru  Nc                 S   s   g | ]	}|j tkr|qS r^   )rZ  r   )r\  wr^   r^   r_   r^  C  s    z6test_xfail_count_with_no_fast_fail.<locals>.<listcomp>c                 S   s   g | ]}|j tkqS r^   )rZ  r   r[  r^   r^   r_   r^  D  r  c                 S   s   g | ]
}|d  dkr|qS )rv  xfailr^   )r\  logr^   r^   r_   r^  G  s    )r   r!   r   r`  ra  r7   r  )r  r  rc  logsxfail_warnsxfailedr^   r^   r_   "test_xfail_count_with_no_fast_fail3  s   r  c                     s   ddddd  fdd} t  }t|}t|dksJ tjdd t||d| d W d   n1 s5w   Y  ttt|dd	} d
 t|ksNJ  d dksVJ  d dks^J  d | d
   d  ksnJ dS )z:Test that the callback is called with the right arguments.r   r  skippedr  r  c                    s    |dv sJ  |  d7  < d S )Nr  r   r^   )rw  ry  rx  rv  rz  r{  
call_countr^   r_   callbackO  s   	z/test_check_estimator_callback.<locals>.callbackTrV  N)r  ru  r  r  r  r  r  r  )r   r!   r   r`  ra  r7   r  rO   )r  r  r  all_checks_countr^   r  r_   test_check_estimator_callbackK  s(   r  c                  C   s   t rc   )r%   r$   r#   r"   r7   )minimal_estimatorsrw  r^   r^   r_   (test_minimal_class_implementation_checksr  s   r  c                  C   sp   G dd dt } ttdd td| dd W d    n1 s!w   Y  td| dd td| d	d d S )
Nc                   @   s2   e Zd ZdddZdd Zedd dd	 Zd
S )z1test_check_fit_check_is_fitted.<locals>.Estimator	attributec                 S   rv   rc   behavior)re   r"  r^   r^   r_   rx   ~  ry   z:test_check_fit_check_is_fitted.<locals>.Estimator.__init__c                 [   s(   | j dkr
d| _| S | j dkrd| _| S )Nr   Trm  )r"  
is_fitted_
_is_fitted)re   rf   rg   r   r^   r^   r_   rh     s   

z5test_check_fit_check_is_fitted.<locals>.Estimator.fitc                 S   s
   | j dv S )N>   rm  always-truer!  r  r^   r^   r_   <lambda>  s   
 z:test_check_fit_check_is_fitted.<locals>.Estimator.<lambda>c                 S   s   | j dkrdS t| dS )Nr%  Tr$  )r"  r3  r  r^   r^   r_   __sklearn_is_fitted__  s   

zGtest_check_fit_check_is_fitted.<locals>.Estimator.__sklearn_is_fitted__N)r   )rZ   r[   r\   rx   rh   rS   r'  r^   r^   r^   r_   r  }  s
    

r  z'passes check_is_fitted before being fitr>  rw  r%  r!  rm  r   )r   r'   	ExceptionrA   )r  r^   r^   r_   test_check_fit_check_is_fitted|  s   r)  c                  C   s^   G dd dt } tjdd}td|   W d    n1 sw   Y  dd |D r-J d S )Nc                   @   r   )z-test_check_requires_y_none.<locals>.Estimatorc                 S   s   t ||\}}d S rc   )rW   rd   r^   r^   r_   rh     r  z1test_check_requires_y_none.<locals>.Estimator.fitNr   r^   r^   r^   r_   r    r   r  TrV  rw  c                 S   rX  r^   )message)r\  r   r^   r^   r_   r^    r_  z.test_check_requires_y_none.<locals>.<listcomp>)r   r`  ra  rL   )r  rW  r^   r^   r_   test_check_requires_y_none  s
   r+  c                  C   sx   t ttfD ]4} tt|  dd}t|v sJ t|v sJ G dd d| }tt| dd}t|vs3J t|vs9J qd S )NTr  c                          e Zd Z fddZ  ZS )z@test_non_deterministic_estimator_skip_tests.<locals>.MyEstimatorc                    s   t   }d|_|S r,  )r   r  non_deterministicr   r   r^   r_   r    s   
zQtest_non_deterministic_estimator_skip_tests.<locals>.MyEstimator.__sklearn_tags__rZ   r[   r\   r  r   r^   r^   r   r_   MyEstimator      r/  )r$   r#   r"   r  r*   rC   rD   )r  	all_testsr/  r^   r^   r_   +test_non_deterministic_estimator_skip_tests  s   r2  c               	   C   sH  G dd dt t} |  }t|jj|du sJ G dd d| }| }d}tt|d t|jj| W d   n1 s<w   Y  ttdd	d
dg|j	d< | }t|jj| tt
ddd
dttddd
dttddd
dttdd	ddg}d}|D ](}|g|j	d< | }tt|d t|jj| W d   n1 sw   Y  qydS )zHCheck the test for the contamination parameter in the outlier detectors.c                   @   s.   e Zd ZdZd
ddZdddZddd	ZdS )zJtest_check_outlier_contamination.<locals>.OutlierDetectorWithoutConstraintz.Outlier detector without parameter validation.皙?c                 S   rv   rc   )contamination)re   r4  r^   r^   r_   rx     ry   zStest_check_outlier_contamination.<locals>.OutlierDetectorWithoutConstraint.__init__Nc                 S   rb   rc   r^   )re   rf   rg   r   r^   r^   r_   rh     ri   zNtest_check_outlier_contamination.<locals>.OutlierDetectorWithoutConstraint.fitc                 S   rj   rk   rl   rd   r^   r^   r_   rq     rr   zRtest_check_outlier_contamination.<locals>.OutlierDetectorWithoutConstraint.predict)r3  r  rc   r   r^   r^   r^   r_    OutlierDetectorWithoutConstraint  s
    

r5  Nc                   @   s   e Zd ZdedhgiZdS )zGtest_check_outlier_contamination.<locals>.OutlierDetectorWithConstraintr4  autoN)rZ   r[   r\   r   _parameter_constraintsr^   r^   r^   r_   OutlierDetectorWithConstraint  r0  r8  zDcontamination constraints should contain a Real Interval constraint.r>  r   g      ?right)closedr4  r   r  r   leftz<contamination constraint should be an interval in \(0, 0.5\])r	   r   rG   r   rZ   r'   rE  r   r   r7  r   )r5  detectorr8  r  incorrect_intervalsintervalr^   r^   r_    test_check_outlier_contamination  s8   

r?  c                  C   s   t dd} td|  dS )zCheck that in case with some probabilities ties, we relax the
    ranking comparison with the decision function.
    Non-regression test for:
    https://github.com/scikit-learn/scikit-learn/issues/24025
    log_loss)lossr   N)r   r4   )rw  r^   r^   r_   test_decision_proba_tie_ranking  s   
rB  c                     sx   t  } tt| dd}tt| dd}t|t|ksJ dd   fdd|D } fdd|D }||s:J d S )	NTr  Fc                 S   s$   z| j W S  ty   | jj  Y S w rc   )rZ   r  func)r  r^   r^   r_   get_check_name  s
   z4test_yield_all_checks_legacy.<locals>.get_check_namec                       h | ]} |qS r^   r^   r\  r  rD  r^   r_   	<setcomp>      z/test_yield_all_checks_legacy.<locals>.<setcomp>c                    rE  r^   r^   rF  rG  r^   r_   rH    rI  )r"   r  r*   r   issubset)rw  legacy_checksnon_legacy_checksnon_legacy_check_nameslegacy_check_namesr^   rG  r_   test_yield_all_checks_legacy  s   rO  c                  C   V   G dd dt } |  }d}tt|d td| W d   dS 1 s$w   Y  dS )zICheck that the right error is raised when the estimator is not cloneable.c                   @   r   )z:test_check_estimator_cloneable_error.<locals>.NotCloneablec                 S      t d)Nz This estimator is not cloneable.NotImplementedErrorr  r^   r^   r_   __sklearn_clone__     zLtest_check_estimator_cloneable_error.<locals>.NotCloneable.__sklearn_clone__N)rZ   r[   r\   rT  r^   r^   r^   r_   NotCloneable  r   rV  zCloning of .* failed with errorr>  N)r   r'   rE  r8   )rV  rw  rL  r^   r^   r_   $test_check_estimator_cloneable_error	     "rW  c                  C   rP  )zMCheck that the right error is raised when the estimator does not have a repr.c                   @   r   )z*test_estimator_repr_error.<locals>.NotReprc                 S   rQ  )Nz$This estimator does not have a repr.rR  r  r^   r^   r_   __repr__  rU  z3test_estimator_repr_error.<locals>.NotRepr.__repr__N)rZ   r[   r\   rY  r^   r^   r^   r_   NotRepr  r   rZ  zRepr of .* failed with errorr>  N)r   r'   rE  r9   )rZ  rw  rL  r^   r^   r_   test_estimator_repr_error  rX  r[  c                  C   s   G dd d} G dd d}G dd d}d}t t|d td|   W d    n1 s.w   Y  t t|d td|  W d    n1 sJw   Y  td|  d S )	Nc                   @   r   )z8test_check_estimator_tags_renamed.<locals>.BadEstimator1c                 S   r  rc   r^   r  r^   r^   r_   
_more_tags%  ri   zCtest_check_estimator_tags_renamed.<locals>.BadEstimator1._more_tagsN)rZ   r[   r\   r\  r^   r^   r^   r_   BadEstimator1$  r   r]  c                   @   r   )z8test_check_estimator_tags_renamed.<locals>.BadEstimator2c                 S   r  rc   r^   r  r^   r^   r_   	_get_tags)  ri   zBtest_check_estimator_tags_renamed.<locals>.BadEstimator2._get_tagsN)rZ   r[   r\   r^  r^   r^   r^   r_   BadEstimator2(  r   r_  c                   @   r`   )z8test_check_estimator_tags_renamed.<locals>.OkayEstimatorc                 S   r  rc   r^   r  r^   r^   r_   r  -  ri   zItest_check_estimator_tags_renamed.<locals>.OkayEstimator.__sklearn_tags__c                 S   r  rc   r^   r  r^   r^   r_   r\  0  ri   zCtest_check_estimator_tags_renamed.<locals>.OkayEstimator._more_tagsN)rZ   r[   r\   r  r\  r^   r^   r^   r_   OkayEstimator,  rt   r`  z.has defined either `_more_tags` or `_get_tags`r>  )r'   rH  r=   )r]  r_  r`  rL  r^   r^   r_   !test_check_estimator_tags_renamed#  s   ra  c                  C   sR   G dd dt } d}tt|d td|   W d   dS 1 s"w   Y  dS )zeCheck that when the estimator has the wrong tags.classifier_tags.multi_class
    set, the test fails.c                   @   r   )zEtest_check_classifier_not_supporting_multiclass.<locals>.BadEstimatorc                 S   rb   rc   r^   rd   r^   r^   r_   rh   F  ri   zItest_check_classifier_not_supporting_multiclass.<locals>.BadEstimator.fitNr   r^   r^   r^   r_   BadEstimatorC  s    rb  z=The estimator tag `tags.classifier_tags.multi_class` is Falser>  N)r   r'   rE  r.   rb  rL  r^   r^   r_   /test_check_classifier_not_supporting_multiclass?  s
   "rd  c               	   C   sR   dD ]$} zt |  W n ty   td|  dw t j| d}t| qd S )N)r   polarszLibrary z is not installed)r   )rB  
__import__r  r%   r   
set_outputr7   )librw  r^   r^   r_   test_estimator_with_set_outputO  s   
ri  c                  C   s   t t } t| sJ dS )z0Check that checks_generator returns a generator.N)rO   r   r   )all_instance_gen_checksr^   r^   r_   test_estimator_checks_generator[  s   
rk  c                   C   sF   t tdd tt ddd d W d   dS 1 sw   Y  dS )zMCheck that check_estimator fails correctly with on_fail='raise' and callback.z9callback cannot be provided together with on_fail='raise'r>  raisec                   S   r  rc   r^   r^   r^   r^   r_   r&  f  s    zDtest_check_estimator_callback_with_fast_fail_error.<locals>.<lambda>)ru  r  N)r'   r   r7   r   r^   r^   r^   r_   2test_check_estimator_callback_with_fast_fail_errora  s
   "rm  c                  C   sZ   G dd dt t} d}ttt|d td|   W d   dS 1 s&w   Y  dS )zFTest that the check raises an error when the mixin order is incorrect.c                   @   r   )z,test_check_mixin_order.<locals>.BadEstimatorNc                 S   rb   rc   r^   rd   r^   r^   r_   rh   m  ri   z0test_check_mixin_order.<locals>.BadEstimator.fitrc   r   r^   r^   r^   r_   rb  l  r   rb  z8TransformerMixin comes before/left side of BaseEstimatorr>  N)r   r
   r'   rE  reescaperE   rc  r^   r^   r_   test_check_mixin_orderi  s
   "rp  c                  C   sN   G dd dt } ttdd td|   W d    d S 1 s w   Y  d S )Nc                       r,  )zHtest_check_positive_only_tag_during_fit.<locals>.RequiresPositiveXBadTagc                    r  r  )r   r  r'  r(  r   r   r^   r_   r  w  r"  zYtest_check_positive_only_tag_during_fit.<locals>.RequiresPositiveXBadTag.__sklearn_tags__r.  r^   r^   r   r_   RequiresPositiveXBadTagv  r0  rq  z5This happens when passing negative input values as X.r>  )r$  r'   rE  rJ   )rq  r^   r^   r_   'test_check_positive_only_tag_during_fitu  s   "rr  )rB  rn  r  r  r`  inspectr   numbersr   r   r  numpyrm   scipy.sparser)  r   sklearnr   r   sklearn.baser   r   r	   r
   sklearn.clusterr   sklearn.datasetsr   r   sklearn.decompositionr   sklearn.exceptionsr   r   r   sklearn.linear_modelr   r   r   r   sklearn.mixturer   sklearn.neighborsr   r   r   sklearn.svmr   r   r   r   r   r   sklearn.utils._param_validationr   r   -sklearn.utils._test_common.instance_generatorr    r!   sklearn.utils._testingr"   r#   r$   r%   r&   r'   sklearn.utils.estimator_checksr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   sklearn.utils.fixesrQ   rR   sklearn.utils.metaestimatorsrS   sklearn.utils.multiclassrT   sklearn.utils.validationrU   rV   rW   rX   r   rY   ra   ru   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.  r1  r4  rF  rM  rP  rR  rU  rd  rf  rg  rh  ri  rj  rp  rq  rs  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rZ   r  r  r  r  r)  r+  r2  r?  rB  rO  rW  r[  ra  rd  ri  rk  rm  rp  rr  r^   r^   r^   r_   <module>   s    +

	%#
	$
/".+|5	
'
6
