U
    ½mœd T  ã                   @   s�  d dl mZmZ d dlZd dlmZ d dl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 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 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# d dlm$Z$ e#egegegegdœƒd¦d dœdd „ƒZ%G d!d"„ d"ƒZ&G d#d$„ d$e	ƒZ'ej( )d%eeg¡d&d'„ ƒZ*d(d)„ Z+ej( )d*eed d+d,d-�eeddd.d-�g¡d/d0„ ƒZ,ej( )d1ed2d3d.d4œe-d5fed+d6d7d4œe-d8fedd d,d4œe.d9fed dd:d4œe.d;fed+d<d.d4œe.d=fg¡d>d?„ ƒZ/d@dA„ Z0dBdC„ Z1ej( )dDe2dEfedEfedFfej3dGfg¡dHdI„ ƒZ4dJdK„ Z5ej( )dLeedd d,d-�eed dd,d-�eeddd7d-�edMdNdOhƒeƒ eƒ edPƒeƒ eƒ g	¡dQdR„ ƒZ6ej( )dSeeddTd:d-�eedUdVd.d-�feeddTd:d-�eedUdVd7d-�feeddTd:d-�eedWdVd.d-�feeddTd:d-�eedVdd,d-�feeddTd:d-�eedWdd7d-�feedTdd,d-�eedUdVd.d-�feedTdd,d-�eedUdVd7d-�feedTdd,d-�eed+d3d.d-�feedTdd,d-�eeddUd,d-�feedTdd,d-�eeddXd7d-�feedUdVd.d-�eedd+d:d-�feedUdVd.d-�eed+dd,d-�feedUdVd.d-�eedYdXd7d-�feedUdVd.d-�eedYdXd:d-�feedUdVd7d-�eedZd[d7d-�feedUdVd7d-�eedZd[d,d-�feed3dd,d-�eed d+d.d-�feed+dd,d-�eed d+d.d-�fg¡d\d]„ ƒZ7ej( )d^eƒ gee8ƒgeƒ geƒ geƒ geƒ geƒ geeddd.d-�geed dd,d-�eedd d7d-�gg	¡d_d`„ ƒZ9ej( )dLeƒ eƒ ee8ƒeƒ eƒ eƒ eƒ eƒ eƒ edMdNdOhƒeed+d3dThƒeeddd7d-�eed d[d7d-�eed dd7d-�eedd d7d-�eed d+d7d-�eed dd.d-�eedd d:d-�edPƒeƒ eƒ g¡dadb„ ƒZ:ej( )dceed d+d.d-�ddfeed dd7d-�defedMdNdOhƒdNfee;ej<ej=hƒej=fe>dfdg„ fdhdid+d3gdTdWggfdie ?d+d3gdTdWgg¡fdjed+d3gdTdWggƒfdkdlej@ Ad ¡fdme&e&ƒ fe2d+fednfdodpdqdrdsdteBduƒfdtejCfdvedPƒe'd dw�fdxg¡dydz„ ƒZDej( )d{eed d+d.d-�efed|d}hƒefeeddd~hƒefdiefdjefdlefdefe>efe2efdefd€efdtefedPƒefd�efg¡d‚dƒ„ ƒZEd„d…„ ZFd†d‡„ ZGdˆd‰„ ZHdŠd‹„ ZIdŒd�„ ZJdŽd�„ ZKd�d‘„ ZLd’d“„ ZMd”d•„ ZNd–d—„ ZOd˜d™„ ZPdšd›„ ZQdœd�„ ZRdždŸ„ ZSd d¡„ ZTd¢d£„ ZUd¤d¥„ ZVdS )§é    )ÚIntegralÚRealN)Ú
csr_matrix)ÚBaseEstimator)ÚLeaveOneOut©Ú
deprecated)ÚHidden)ÚInterval)ÚOptions)Ú
StrOptions)Ú_ArrayLikes)Ú	_Booleans)Ú
_Callables)Ú
_CVObjects)Ú_InstancesOf)Ú_MissingValues)Ú_PandasNAConstraint)Ú_IterablesNotString)Ú_NoneConstraint)Ú_RandomStates)Ú_SparseMatrices)Ú_VerboseHelper)Ú
HasMethods)Úmake_constraint)Úgenerate_invalid_param_val)Úgenerate_valid_param)Úvalidate_params)ÚInvalidParameterError)ÚaÚbÚcÚd)r"   c                O   s   dS )z/A function to test the validation of functions.N© )r   r    r!   r"   ÚargsÚkwargsr#   r#   úb/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/utils/tests/test_param_validation.pyÚ_func#   s    r'   c                   @   sB   e Zd ZdZedegiƒdd„ ƒZeƒ edegiƒdd„ ƒƒZdS )Ú_ClasszJA class to test the _InstancesOf constraint and the validation of methods.r   c                 C   s   dS )zA validated methodNr#   ©Úselfr   r#   r#   r&   Ú_method+   s    z_Class._methodc                 C   s   dS )zA deprecated validated methodNr#   r)   r#   r#   r&   Ú_deprecated_method/   s    z_Class._deprecated_methodN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r+   r   r,   r#   r#   r#   r&   r(   (   s   
r(   c                   @   s6   e Zd ZU dZdegiZeed< dd„ Zd	dd„Z	dS )
Ú
_Estimatorz<An estimator to test the validation of estimator parameters.r   Ú_parameter_constraintsc                 C   s
   || _ d S ©N©r   r)   r#   r#   r&   Ú__init__:   s    z_Estimator.__init__Nc                 C   s   |   ¡  d S r3   )Z_validate_params©r*   ÚXÚyr#   r#   r&   Úfit=   s    z_Estimator.fit)NN)
r-   r.   r/   r0   r   r2   ÚdictÚ__annotations__r5   r9   r#   r#   r#   r&   r1   5   s   
r1   Úinterval_typec                 C   s”   t | dddd�}d|kr d|ks$t‚t | dddd�}d|krDd|ksHt‚t | dddd�}d|krhd|kslt‚t | dddd�}d|krŒd|ks�t‚dS )	z.Check the range of values depending on closed.éþÿÿÿé   Úleft©ÚclosedÚrightÚbothÚneitherN)r
   ÚAssertionError)r<   Úintervalr#   r#   r&   Útest_interval_rangeA   s    rG   c                  C   sp   t tdddd�} tj| kst‚t tdddd�} tj | ks>t‚t tdddd�} tj| ks\t‚tj | kslt‚dS )zjCheck that inf is included iff a bound is closed and set to None.

    Only valid for real intervals.
    r   NrB   r@   r?   rD   )r
   r   ÚnpÚinfrE   ©rF   r#   r#   r&   Útest_interval_inf_in_boundsQ   s    rK   rF   é   r?   r@   rC   c                 C   s   t j| kst‚dS )z)Check that np.nan is not in any interval.N)rH   ÚnanrE   rJ   r#   r#   r&   Útest_nan_not_in_intervala   s    rN   zparams, error, matchç      ð?r>   )Útyper?   rB   rA   z=Expecting left to be an int for an interval over the integersg       @rD   z>Expecting right to be an int for an interval over the integersz&left can't be None when closed == leftrB   z(right can't be None when closed == rightéÿÿÿÿzright can't be less than leftc              	   C   s(   t j||d�� tf | Ž W 5 Q R X dS )zNCheck that informative errors are raised for invalid combination of parameters©ÚmatchN)ÚpytestÚraisesr
   )ÚparamsÚerrorrS   r#   r#   r&   Útest_interval_errorsj   s     rX   c                  C   sR   t dddhdhd�} |  d¡s"t‚|  d¡s0t‚|  d¡r>t‚dt| ƒksNt‚dS )z*Sanity check for the StrOptions constraintr   r    r!   r   r"   z'c' (deprecated)N)r   Úis_satisfied_byrE   Ústr©Úoptionsr#   r#   r&   Útest_stroptionsŽ   s
    r]   c                  C   sX   t tddtjhdhd�} |  d¡s&t‚|  tj¡s6t‚|  d¡rDt‚dt| ƒksTt‚dS )z'Sanity check for the Options constraintg      à¿ç      à?r   ç®Gáz®ó?z-0.5 (deprecated)N)r   r   rH   rI   rY   rE   rZ   r[   r#   r#   r&   Útest_options˜   s
    r`   ztype, expected_type_nameÚintÚfloatznumpy.ndarrayc                 C   s$   t | ƒ}t|ƒd|› d�ks t‚dS )z?Check the string representation of the _InstancesOf constraint.zan instance of 'ú'N)r   rZ   rE   )rP   Zexpected_type_nameÚ
constraintr#   r#   r&   Ú%test_instances_of_type_human_readable¢   s    re   c                  C   s\   t ddgƒ} G dd„ dƒ}G dd„ dƒ}|  |ƒ ¡s8t‚|  |ƒ ¡rHt‚t| ƒdksXt‚dS )	z Check the HasMethods constraint.r   r    c                   @   s   e Zd Zdd„ Zdd„ ZdS )ztest_hasmethods.<locals>._Goodc                 S   s   d S r3   r#   ©r*   r#   r#   r&   r   ¶   s    z test_hasmethods.<locals>._Good.ac                 S   s   d S r3   r#   rf   r#   r#   r&   r    ¹   s    z test_hasmethods.<locals>._Good.bN)r-   r.   r/   r   r    r#   r#   r#   r&   Ú_Goodµ   s   rg   c                   @   s   e Zd Zdd„ ZdS )ztest_hasmethods.<locals>._Badc                 S   s   d S r3   r#   rf   r#   r#   r&   r   ½   s    ztest_hasmethods.<locals>._Bad.aN)r-   r.   r/   r   r#   r#   r#   r&   Ú_Bad¼   s   rh   z"an object implementing 'a' and 'b'N)r   rY   rE   rZ   )rd   rg   rh   r#   r#   r&   Útest_hasmethods±   s    ri   rd   r   r    r!   r9   c                 C   s   t | ƒ}|  |¡rt‚dS )z>Check that the value generated does not satisfy the constraintN©r   rY   rE   )rd   Ú	bad_valuer#   r#   r&   Útest_generate_invalid_param_valÅ   s    rl   zinteger_interval, real_intervalé   éûÿÿÿé   é   éüÿÿÿiöÿÿÿé   é
   c                 C   s\   t ||| gd�}| |¡rt‚|  |¡r,t‚t | || gd�}| |¡rJt‚|  |¡rXt‚dS )ztCheck that the value generated for an interval constraint does not satisfy any of
    the interval constraints.
    ©ÚconstraintsNrj   )Zinteger_intervalZreal_intervalrk   r#   r#   r&   Ú+test_generate_invalid_param_val_2_intervalsÙ   s    Q ÿ ÿrv   ru   c              	   C   s*   t  t¡� t| d | d� W 5 Q R X dS )zmCheck that the function raises NotImplementedError when there's no invalid value
    for the constraint.
    r   rt   N)rT   rU   ÚNotImplementedErrorr   rt   r#   r#   r&   Ú)test_generate_invalid_param_val_all_valid7  s    rx   c                 C   s   t | ƒ}|  |¡st‚dS )z;Check that the value generated does satisfy the constraint.N)r   rY   rE   )rd   Úvaluer#   r#   r&   Útest_generate_valid_paramP  s    rz   zconstraint_declaration, valuegáz®GáÚ?é*   c                 C   s   | d S )NrL   r#   )Úxr#   r#   r&   Ú<lambda>w  ó    r}   )NNz
array-likezsparse matrix)Úrandom_stater   r   )r   Nr^   )ÚbooleanF)ÚverboserL   )Úmissing_valuesrQ   )r‚   g      ð¿)r‚   Nr‚   rM   )r‚   Úmissingr4   )Ú	cv_objectro   c                 C   s   t | ƒ}| |¡st‚dS )z+Sanity check for the is_satisfied_by methodN)r   rY   rE   )Úconstraint_declarationry   rd   r#   r#   r&   Útest_is_satisfied_byp  s     r†   z1constraint_declaration, expected_constraint_classZoption1Zoption2r_   r€   r�   r„   c                 C   s   t | ƒ}|j|kst‚dS )zHCheck that make_constraint dispaches to the appropriate constraint classN)r   Ú	__class__rE   )r…   Zexpected_constraint_classrd   r#   r#   r&   Útest_make_constraint”  s    rˆ   c                	   C   s&   t jtdd�� tdƒ W 5 Q R X dS )zNCheck that an informative error is raised when an unknown constraint is passedzUnknown constraintrR   znot a valid constraintN)rT   rU   Ú
ValueErrorr   r#   r#   r#   r&   Útest_make_constraint_unknown­  s    rŠ   c                	   C   s  t jtdd�� tddd� W 5 Q R X t jtdd�� tddgddiŽ W 5 Q R X t jtdd�� tdddiŽ W 5 Q R X t jtd	d�� tdddd
� W 5 Q R X t jtdd��& tddddgžddiddi—Ž W 5 Q R X t jtdd��& tddddgžddiddi—Ž W 5 Q R X dS )zGCheck that validate_params works no matter how the arguments are passedz"The 'a' parameter of _func must berR   ÚwrongrL   ©r!   z"The 'b' parameter of _func must ber!   ú"The 'c' parameter of _func must bez"The 'd' parameter of _func must be)r!   r"   r   r>   rm   rp   Úero   ÚfourN)rL   )r   )r   )rT   rU   r   r'   r#   r#   r#   r&   Útest_validate_params³  s<     ÿ ÿ ÿ ÿ ÿ* ÿr�   c                  C   s$   t dtgiƒdd„ ƒ} | ddƒ dS )zTCheck that no error is raised when there are parameters without
    constraints
    r   c                 S   s   d S r3   r#   )r   r    r#   r#   r&   ÚfuncÚ  s    z1test_validate_params_missing_params.<locals>.funcrL   r>   N)r   ra   )r‘   r#   r#   r&   Ú#test_validate_params_missing_paramsÕ  s    
r’   c               
   C   sx   t ƒ tƒ} tjtdd�� | dddd� W 5 Q R X tjtdd��. tjtdd�� | dddd� W 5 Q R X W 5 Q R X d	S )
z5Check that validate_params functions can be decoratedzFunction _func is deprecatedrR   rL   r>   rm   rŒ   r�   r‹   N)r   r'   rT   ÚwarnsÚFutureWarningrU   r   )Zdecorated_functionr#   r#   r&   Ú test_decorate_validated_functioná  s    
 ÿr•   c                
   C   sj   t jtdd�� tƒ  d¡ W 5 Q R X t jtdd��, t jtdd�� tƒ  d¡ W 5 Q R X W 5 Q R X dS )z-Check that validate_params works with methodsz+The 'a' parameter of _Class._method must berR   r‹   z)Function _deprecated_method is deprecatedz6The 'a' parameter of _Class._deprecated_method must beN)rT   rU   r   r(   r+   r“   r”   r,   r#   r#   r#   r&   Útest_validate_params_methodð  s     ÿþr–   c               	   C   s.   t dƒ} tjtdd�� |  ¡  W 5 Q R X dS )z9Check that validate_params works with Estimator instancesr‹   z'The 'a' parameter of _Estimator must berR   N)r1   rT   rU   r   r9   )Zestr#   r#   r&   Útest_validate_params_estimator   s     ÿr—   c                	   C   s4   t jtdd�� tdddhddhd� W 5 Q R X dS )	z@Check that the deprecated parameter must be a subset of options.z#deprecated options must be a subsetrR   r   r    r!   r"   r   N)rT   rU   r‰   r   r#   r#   r#   r&   Ú!test_stroptions_deprecated_subset  s    r˜   c               	   C   s„   t dttƒtgiƒdd„ ƒ} | ddddœƒ | dddgƒ tjtdd	��}| d
d� W 5 Q R X t|jƒ}d|kstt	‚d|ks€t	‚dS )zECheck that internal constraints are not exposed in the error message.Úparamc                 S   s   d S r3   r#   ©r™   r#   r#   r&   Úf  s    z!test_hidden_constraint.<locals>.frL   r>   rm   )r   r    r!   úThe 'param' parameterrR   Úbadrš   zan instance of 'dict'zan instance of 'list'N)
r   r	   Úlistr:   rT   rU   r   rZ   ry   rE   ©r›   Úexc_infoÚerr_msgr#   r#   r&   Útest_hidden_constraint  s    
 ÿ
r¢   c               	   C   s‚   t dtdhƒttdhƒƒgiƒdd„ ƒ} | dƒ | dƒ tjtdd��}| dd	� W 5 Q R X t|jƒ}d|ksrt‚d|ks~t‚d
S )zBCheck that we can have 2 StrOptions constraints, one being hidden.r™   ÚautoÚwarnc                 S   s   d S r3   r#   rš   r#   r#   r&   r›   *  s    z!test_hidden_stroptions.<locals>.frœ   rR   r�   rš   N)	r   r   r	   rT   rU   r   rZ   ry   rE   rŸ   r#   r#   r&   Útest_hidden_stroptions'  s    
 ÿ
r¥   c                   C   s$   t tdƒst‚t tƒ jdƒs t‚dS )zˆCheck that the validate_params decorator properly sets the parameter constraints
    as attribute of the decorated function/method.
    Z_skl_parameter_constraintsN)Úhasattrr'   rE   r(   r+   r#   r#   r#   r&   Ú4test_validate_params_set_param_constraints_attribute=  s    r§   c               	   C   sR   t ddgiƒdd„ ƒ} | dƒ | t d¡ƒ tjtdd�� | d	ƒ W 5 Q R X d
S )z’Check that validate_params raise a deprecation message but still passes
    validation when using an int for a parameter accepting a boolean.
    r™   r€   c                 S   s   d S r3   r#   rš   r#   r#   r&   r›   J  s    z1test_boolean_constraint_deprecated_int.<locals>.fTFz4Passing an int for a boolean parameter is deprecatedrR   rL   N)r   rH   Zbool_rT   r“   r”   )r›   r#   r#   r&   Ú&test_boolean_constraint_deprecated_intE  s    
 ÿr¨   c               	   C   sh   t tdgddœƒddd„ƒ} tjtdd�� | dd	� W 5 Q R X G d
d„ dƒ}| |d� | |ƒ d� dS )z5Check that validation can be skipped for a parameter.NZno_validation©Úparam1Úparam2c                 S   s   d S r3   r#   r©   r#   r#   r&   r›   \  s    ztest_no_validation.<locals>.fzThe 'param1' parameterrR   r‹   )rª   c                   @   s   e Zd ZdS )z$test_no_validation.<locals>.SomeTypeN)r-   r.   r/   r#   r#   r#   r&   ÚSomeTypee  s   r¬   )r«   )NN)r   ra   rT   rU   r   )r›   r¬   r#   r#   r&   Útest_no_validationY  s    
r­   c                  C   s>   t  d¡} tƒ }| | j¡s t‚| t dddg¡¡r:t‚dS )z9Add a specific test for checking support for `pandas.NA`.ZpandasrL   r>   rm   N)rT   Zimportorskipr   rY   ZNArE   rH   Úarray)ÚpdZna_constraintr#   r#   r&   Ú$test_pandas_na_constraint_with_pd_nal  s    
r°   c                  C   s>   t ƒ } |  dddg¡st‚|  tdƒ¡s,t‚|  d¡r:t‚dS )zGCheck that a string does not satisfy the _IterableNotString constraint.rL   r>   rm   rs   zsome stringN)r   rY   rE   Úrange©rd   r#   r#   r&   Útest_iterable_not_stringu  s    r³   c                  C   sn   t ƒ } |  d¡st‚|  tƒ ¡s$t‚|  ddgddgfddgddgfg¡sNt‚|  d¡s\t‚|  d¡rjt‚dS )zUCheck that the _CVObjects constraint accepts all current ways
    to pass cv objects.ro   rL   r>   rm   rp   Nznot a CV object)r   rY   rE   r   r²   r#   r#   r&   Útest_cv_objects}  s    *r´   c                  C   s"   G dd„ dt ƒ} | dd� ¡  dS )zÆCheck that the validation from a scikit-learn estimator inherited by a third
    party estimator does not impose a match between the dict of constraints and the
    parameters of the estimator.
    c                       s*   e Zd Z‡ fdd„Zd‡ fdd„	Z‡  ZS )z7test_third_party_estimator.<locals>.ThirdPartyEstimatorc                    s   || _ tƒ jdd� d S )Nr   r4   )r    Úsuperr5   )r*   r    ©r‡   r#   r&   r5   �  s    z@test_third_party_estimator.<locals>.ThirdPartyEstimator.__init__Nc                    s   t ƒ  ||¡ d S r3   )rµ   r9   r6   r¶   r#   r&   r9   “  s    z;test_third_party_estimator.<locals>.ThirdPartyEstimator.fit)NN)r-   r.   r/   r5   r9   Ú__classcell__r#   r#   r¶   r&   ÚThirdPartyEstimatorŽ  s   r¸   r   )r    N)r1   r9   )r¸   r#   r#   r&   Útest_third_party_estimatorˆ  s    
r¹   c                  C   s0   t ddddd�} |  d¡st‚|  d¡r,t‚dS )z=Check for the type "real_not_int" in the Interval constraint.Zreal_not_intr   rL   rC   r@   rO   N)r
   rY   rE   r²   r#   r#   r&   Útest_interval_real_not_int›  s    rº   )r   )WÚnumbersr   r   ÚnumpyrH   Zscipy.sparser   rT   Zsklearn.baser   Zsklearn.model_selectionr   Zsklearn.utilsr   Zsklearn.utils._param_validationr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'   r(   r1   ÚmarkZparametrizerG   rK   rN   Ú	TypeErrorr‰   rX   r]   r`   ra   Zndarrayre   ri   rl   rv   rž   rx   rz   rP   Zfloat32Zfloat64Úcallabler®   ÚrandomZRandomStaterb   rM   r†   rˆ   rŠ   r�   r’   r•   r–   r—   r˜   r¢   r¥   r§   r¨   r­   r°   r³   r´   r¹   rº   r#   r#   r#   r&   Ú<module>   s  
þ
ýýýýýëþ


üþ	
÷þ
þþþþþþþþþþþþþþþþþþ»þM
þ÷þ
ëþ


çþ

òþ
"	