a
    h5_                     @   s  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 d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* d d	l+m,Z, e*egegegegd
dddd dddZ-G dd dZ.G dd deZ/ej01deegdd Z2ej01deegdd Z3dd Z4ej01deed dddeeddddgd d! Z5ej01d"ed#d$dd%e6d&fedd'd(d%e6d)fedd dd%e7d*fed dd+d%e7d,fedd-dd%e7d.fgd/d0 Z8d1d2 Z9d3d4 Z:ej01d5e;d6fed6fed7fej<d8fgd9d: Z=d;d< Z>ej01d=eedd ddeed dddeeddd(deh d>e edd?e& ed@e  e g
dAdB Z?ej01dCeeddDd+deedEdFddfeeddDd+deedEdFd(dfeeddDd+deedGdFddfeeddDd+deedFdddfeeddDd+deedGdd(dfeedDdddeedEdFddfeedDdddeedEdFd(dfeedDdddeedd$ddfeedDdddeeddEddfeedDdddeeddHd(dfeedEdFddeeddd+dfeedEdFddeeddddfeedEdFddeedIdHd(dfeedEdFddeedIdHd+dfeedEdFd(deedJdKd(dfeedEdFd(deedJdKddfeed$dddeed dddfeeddddeed dddfgdLdM Z@ej01d=e eeAe e" e$ e% e eeddd(dgdNdO ZBej01d=e e eeAe" e$ e% e e& e edd?eh d>eeh dPeeddd(deed dKd(deed dd(deedd d(deed dd(deed dddeedd d+ded@e  e gdQdR ZCej01dSeed ddddTfeed dd(ddUfeh d>dVfeeDejEejFhejFfeGdWdX fdYdZdd$gdDdGggfdZeHdd$gdDdGggfd[edd$gdDdGggfg	d\d] e,D d^d_ejIJd fd`e.e. fe;dfedafdbdcddejKfe d-fe defe d$df fe dfe eLddfe ejKfe dgfed@e/d dhfdidjdk ZMej01dleed dddefedmdnhefeedTdohefdZefd[e%fd_e$fde"feGefe;efdpefdqe&fedd?efed@efdrefdde!fgdsdt ZNdudv ZOdwdx ZPdydz ZQd{d| ZRd}d~ ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zaej01dddgdd Zbej01dg ddd ZcdS )    )IntegralRealN)
csr_matrix)config_context
get_config)BaseEstimator_fit_context)LeaveOneOut
deprecated)
HasMethodsHiddenIntervalInvalidParameterErrorMissingValuesOptions
RealNotInt
StrOptions_ArrayLikes	_Booleans
_Callables
_CVObjects_InstancesOf_IterablesNotString_NanConstraint_NoneConstraint_PandasNAConstraint_RandomStates_SparseMatrices_VerboseHelpergenerate_invalid_param_valgenerate_valid_parammake_constraintvalidate_params)CSR_CONTAINERS)abcdTprefer_skip_nested_validation)r(   c                O   s   dS )z/A function to test the validation of functions.N )r%   r&   r'   r(   argskwargsr+   r+   e/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/utils/tests/test_param_validation.py_func)   s    r/   c                   @   sJ   e Zd ZdZedegidddd Ze edegidddd Zd	S )
_ClasszJA class to test the _InstancesOf constraint and the validation of methods.r%   Tr)   c                 C   s   dS )zA validated methodNr+   selfr%   r+   r+   r.   _method4   s    z_Class._methodc                 C   s   dS )zA deprecated validated methodNr+   r1   r+   r+   r.   _deprecated_method8   s    z_Class._deprecated_methodN)	__name__
__module____qualname____doc__r#   r   r3   r   r4   r+   r+   r+   r.   r0   1   s   
r0   c                   @   s@   e Zd ZU dZdegiZeed< dd Ze	dd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%   r1   r+   r+   r.   __init__C   s    z_Estimator.__init__Tr)   Nc                 C   s   d S r;   r+   r2   Xyr+   r+   r.   fitF   s    z_Estimator.fit)NN)r5   r6   r7   r8   r   r:   dict__annotations__r=   r   rA   r+   r+   r+   r.   r9   >   s
   
r9   interval_typec                 C   s   t | dddd}d|v sJ d|vs(J t | dddd}d|vsDJ d|v sPJ t | dddd}d|v slJ d|v sxJ t | dddd}d|vsJ d|vsJ dS )	z.Check the range of values depending on closed.   leftclosedrightbothneitherN)r   rD   intervalr+   r+   r.   test_interval_rangeK   s    rO   c                 C   s   t | dddd}dd |vs J dd |vs0J tdd |vsDJ tdd |vsXJ t | ddd dd}dd |v s|J dd |vsJ tdd |v sJ tdd |vsJ dd |vsJ dS )	zbCheck that Interval constraint work with large integers.

    non-regression test for #26648.
    r   rF   rL   rH   A      i   N)r   floatrM   r+   r+   r.   test_interval_large_integers_   s    rS   c                  C   sp   t tdddd} tj| v sJ t tdddd} tj | v s>J t tdddd} tj| vs\J tj | vslJ dS )zjCheck that inf is included iff a bound is closed and set to None.

    Only valid for real intervals.
    r   NrJ   rH   rG   rL   )r   r   npinfrN   r+   r+   r.   test_interval_inf_in_boundst   s    rW   rN      rG   rH   rK   c                 C   s   t j| vsJ dS )z)Check that np.nan is not in any interval.N)rT   nanrV   r+   r+   r.   test_nan_not_in_interval   s    rZ   zparams, error, match      ?rF   )typerG   rJ   rI   z=Expecting left to be an int for an interval over the integersg       @rL   z>Expecting right to be an int for an interval over the integersz&left can't be None when closed == leftrJ   z(right can't be None when closed == rightzright can't be less than leftc                 C   s@   t j||d tf i |  W d   n1 s20    Y  dS )zNCheck that informative errors are raised for invalid combination of parametersmatchN)pytestraisesr   )paramserrorr_   r+   r+   r.   test_interval_errors   s     rd   c                  C   sP   t h ddhd} | ds J | ds.J | dr<J dt| v sLJ dS )z*Sanity check for the StrOptions constraint   r&   r%   r'   r'   r
   r%   r(   z'c' (deprecated)N)r   is_satisfied_bystroptionsr+   r+   r.   test_stroptions   s
    rj   c                  C   sX   t tddtjhdhd} | ds&J | tjs6J | drDJ dt| v sTJ dS )z'Sanity check for the Options constraintg            ?r
   Gz?z-0.5 (deprecated)N)r   r   rT   rU   rf   rg   rh   r+   r+   r.   test_options   s
    rm   ztype, expected_type_nameintrR   znumpy.ndarrayc                 C   s$   t | }t|d| dks J dS )z?Check the string representation of the _InstancesOf constraint.zan instance of ''N)r   rg   )r\   Zexpected_type_name
constraintr+   r+   r.   %test_instances_of_type_human_readable   s    rq   c                  C   s\   t ddg} G dd d}G dd d}| | s8J | | rHJ t| dksXJ 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 r;   r+   r2   r+   r+   r.   r%      s    z test_hasmethods.<locals>._Good.ac                 S   s   d S r;   r+   rr   r+   r+   r.   r&      s    z test_hasmethods.<locals>._Good.bN)r5   r6   r7   r%   r&   r+   r+   r+   r.   _Good   s   rs   c                   @   s   e Zd Zdd ZdS )ztest_hasmethods.<locals>._Badc                 S   s   d S r;   r+   rr   r+   r+   r.   r%      s    ztest_hasmethods.<locals>._Bad.aN)r5   r6   r7   r%   r+   r+   r+   r.   _Bad   s   rt   z"an object implementing 'a' and 'b'N)r   rf   rg   )rp   rs   rt   r+   r+   r.   test_hasmethods   s    ru   rp   re   )Znumeric_onlyrA   c                 C   s   t | }| |rJ dS )z>Check that the value generated does not satisfy the constraintNr    rf   )rp   	bad_valuer+   r+   r.   test_generate_invalid_param_val   s    rx   zinteger_interval, real_interval         i   
   c                 C   sP   t |d}||rJ | |r&J t | d}||r>J | |rLJ dS )ztCheck that the value generated for an interval constraint does not satisfy any of
    the interval constraints.
    rp   Nrv   )Zinteger_intervalZreal_intervalrw   r+   r+   r.   +test_generate_invalid_param_val_2_intervals   s    Q

r   c                 C   s6   t t t|  W d   n1 s(0    Y  dS )zmCheck that the function raises NotImplementedError when there's no invalid value
    for the constraint.
    N)r`   ra   NotImplementedErrorr    r   r+   r+   r.   )test_generate_invalid_param_val_all_validW  s    r   >   rX   rF   ry   c                 C   s   t | }| |sJ dS )z;Check that the value generated does satisfy the constraint.N)r!   rf   )rp   valuer+   r+   r.   test_generate_valid_paraml  s    r   zconstraint_declaration, valuegzG?*   r&   c                 C   s   | d S )NrX   r+   )xr+   r+   r.   <lambda>      r   )NNz
array-likesparse matrixc                 C   s$   g | ]}d |ddgddggfqS )r   rX   rF   ry   r|   r+   ).0	containerr+   r+   r.   
<listcomp>  s   r   )random_stater   r   )r   Nrk   )booleanF)verboserX   rY   g      i  missingr<   )	cv_objectr{   c                 C   s   t | }||sJ dS )z+Sanity check for the is_satisfied_by methodN)r"   rf   )constraint_declarationr   rp   r+   r+   r.   test_is_satisfied_by  s    &r   z1constraint_declaration, expected_constraint_classZoption1Zoption2rl   r   r   r   c                 C   s   t | }|j|u sJ dS )zICheck that make_constraint dispatches to the appropriate constraint classN)r"   	__class__)r   Zexpected_constraint_classrp   r+   r+   r.   test_make_constraint  s    r   c                   C   s:   t jtdd td W d   n1 s,0    Y  dS )zNCheck that an informative error is raised when an unknown constraint is passedzUnknown constraintr^   znot a valid constraintN)r`   ra   
ValueErrorr"   r+   r+   r+   r.   test_make_constraint_unknown  s    r   c                   C   s  t jtdd tddd W d   n1 s00    Y  t jtdd" tddgddi W d   n1 sp0    Y  t jtd	d" tdi ddi W d   n1 s0    Y  t jtd
d tdddd W d   n1 s0    Y  t jtdd2 tdgg dR ddiddi W d   n1 s>0    Y  t jtd	d2 tdgg dR ddiddi W d   n1 s0    Y  dS )zGCheck that validate_params works no matter how the arguments are passedz"The 'a' parameter of _func must ber^   wrongrX   r'   Nz"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   rF   ry   r|   er{   rX   rF   ry   four)rX   )r`   ra   r   r/   r+   r+   r+   r.   test_validate_params  s0    *00,Br   c                  C   s(   t dtgidddd } | dd dS )	zTCheck that no error is raised when there are parameters without
    constraints
    r%   Tr)   c                 S   s   d S r;   r+   )r%   r&   r+   r+   r.   func  s    z1test_validate_params_missing_params.<locals>.funcrX   rF   N)r#   rn   )r   r+   r+   r.   #test_validate_params_missing_params  s    
r   c               	   C   s   t  t} tjtdd | dddd W d   n1 s<0    Y  tjtddL tjtdd | ddd	d W d   n1 s0    Y  W d   n1 s0    Y  dS )
z5Check that validate_params functions can be decoratedzFunction _func is deprecatedr^   rX   rF   ry   r   Nr   r   )r   r/   r`   warnsFutureWarningra   r   )Zdecorated_functionr+   r+   r.    test_decorate_validated_function  s    
,r   c                	   C   s   t jtdd t d W d   n1 s00    Y  t jtddJ t jtdd t d W d   n1 sz0    Y  W d   n1 s0    Y  dS )z-Check that validate_params works with methodsz+The 'a' parameter of _Class._method must ber^   r   Nz)Function _deprecated_method is deprecatedz6The 'a' parameter of _Class._deprecated_method must be)r`   ra   r   r0   r3   r   r   r4   r+   r+   r+   r.   test_validate_params_method  s    *r   c                  C   sB   t d} tjtdd |   W d   n1 s40    Y  dS )z9Check that validate_params works with Estimator instancesr   z'The 'a' parameter of _Estimator must ber^   N)r9   r`   ra   r   rA   )Zestr+   r+   r.   test_validate_params_estimator$  s
    r   c                   C   sF   t jtdd$ th dddhd W d   n1 s80    Y  dS )z@Check that the deprecated parameter must be a subset of options.z#deprecated options must be a subsetr^   re   r%   r(   r
   N)r`   ra   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	 | g d
 tjtdd}| dd W d   n1 sj0    Y  t|j}d|v sJ d|vsJ dS )zECheck that internal constraints are not exposed in the error message.paramTr)   c                 S   s   d S r;   r+   r   r+   r+   r.   f8  s    z!test_hidden_constraint.<locals>.frX   rF   ry   )r%   r&   r'   r   The 'param' parameterr^   badr   Nzan instance of 'dict'zan instance of 'list')	r#   r   listrB   r`   ra   r   rg   r   r   exc_infoerr_msgr+   r+   r.   test_hidden_constraint5  s    
(
r   c                  C   s   t dtdhttdhgidddd } | d | d tjtdd	}| d
d W d   n1 sj0    Y  t|j}d|v sJ d|vsJ dS )zBCheck that we can have 2 StrOptions constraints, one being hidden.r   autowarnTr)   c                 S   s   d S r;   r+   r   r+   r+   r.   r   P  s    z!test_hidden_stroptions.<locals>.fr   r^   r   r   N)r#   r   r   r`   ra   r   rg   r   r   r+   r+   r.   test_hidden_stroptionsM  s    
(
r   c                   C   s$   t tdsJ t t jds J dS )zCheck that the validate_params decorator properly sets the parameter constraints
    as attribute of the decorated function/method.
    Z_skl_parameter_constraintsN)hasattrr/   r0   r3   r+   r+   r+   r.   4test_validate_params_set_param_constraints_attributef  s    r   c                  C   s4   t ddgidddd } | d | td dS )	zCheck that validate_params raise a deprecation message but still passes
    validation when using an int for a parameter accepting a boolean.
    r   r   Tr)   c                 S   s   d S r;   r+   r   r+   r+   r.   r   s  s    z1test_boolean_constraint_deprecated_int.<locals>.fFN)r#   rT   Zbool_r   r+   r+   r.   &test_boolean_constraint_deprecated_intn  s    
r   c                  C   s   t tdgddddddd} tjtdd	 | d
d W d   n1 sN0    Y  G dd d}| |d | | d dS )z5Check that validation can be skipped for a parameter.NZno_validationparam1param2Tr)   c                 S   s   d S r;   r+   r   r+   r+   r.   r     s    ztest_no_validation.<locals>.fzThe 'param1' parameterr^   r   )r   c                   @   s   e Zd ZdS )z$test_no_validation.<locals>.SomeTypeN)r5   r6   r7   r+   r+   r+   r.   SomeType  s   r   )r   )NNr#   rn   r`   ra   r   )r   r   r+   r+   r.   test_no_validation|  s    (
r   c                  C   s<   t d} t }|| js J |tg dr8J dS )z9Add a specific test for checking support for `pandas.NA`.Zpandasr   N)r`   Zimportorskipr   rf   ZNArT   array)pdZna_constraintr+   r+   r.   $test_pandas_na_constraint_with_pd_na  s    
r   c                  C   s<   t  } | g dsJ | tds*J | dr8J dS )zGCheck that a string does not satisfy the _IterableNotString constraint.r   r   zsome stringN)r   rf   ranger   r+   r+   r.   test_iterable_not_string  s    r   c                  C   sn   t  } | dsJ | t s$J | ddgddgfddgddgfgsNJ | ds\J | drjJ dS )zUCheck that the _CVObjects constraint accepts all current ways
    to pass cv objects.r{   rX   rF   ry   r|   Nznot a CV object)r   rf   r	   r   r+   r+   r.   test_cv_objects  s    *r   c                  C   s"   G dd dt } | dd  dS )zCheck 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   r<   )r&   superr=   )r2   r&   r   r+   r.   r=     s    z@test_third_party_estimator.<locals>.ThirdPartyEstimator.__init__Nc                    s   t  || d S r;   )r   rA   r>   r   r+   r.   rA     s    z;test_third_party_estimator.<locals>.ThirdPartyEstimator.fit)NN)r5   r6   r7   r=   rA   __classcell__r+   r+   r   r.   ThirdPartyEstimator  s   r   r   r&   N)r9   rA   )r   r+   r+   r.   test_third_party_estimator  s    
r   c                  C   s0   t tdddd} | dsJ | dr,J dS )z9Check for the type RealNotInt in the Interval constraint.r   rX   rK   rH   r[   N)r   r   rf   r   r+   r+   r.   test_interval_real_not_int  s    r   c                   C   sH   t dtsJ t dtrJ t tdts0J t tdtrDJ dS )zCheck for the RealNotInt type.r[   rX   N)
isinstancer   rT   float64Zint64r+   r+   r+   r.   test_real_not_int  s    r   c                  C   s   t dtgidddd } tjtdd | dd	 W d
   n1 sH0    Y  tdd | dd	 W d
   n1 s|0    Y  d
S )z@Check that param validation can be skipped using config_context.r%   Tr)   c                 S   s   d S r;   r+   r<   r+   r+   r.   r     s    z%test_skip_param_validation.<locals>.fThe 'a' parameterr^   1r<   Nskip_parameter_validation)r#   rn   r`   ra   r   r   r   r+   r+   r.   test_skip_param_validation  s    
(r   r*   Fc                    s   t dtgidddd  t dtgi| d fdd}tjtd	d
 |dd W d   n1 sf0    Y  | r|dd n8tjtdd
 |dd W d   n1 s0    Y  dS )z,Check that nested validation can be skipped.r%   Tr)   c                 S   s   d S r;   r+   r<   r+   r+   r.   r     s    z&test_skip_nested_validation.<locals>.fr&   c                    s
    ddS )Ninvalid_param_valuer<   r+   r   r   r+   r.   g  s    z&test_skip_nested_validation.<locals>.gzThe 'b' parameterr^   r   r   NrX   r   r   )r*   r   r+   r   r.   test_skip_nested_validation  s    
(r   zJskip_parameter_validation, prefer_skip_nested_validation, expected_skipped))TTT)TFT)FTT)FFFc                 C   s\   t dtgi|ddd }t| d |d}W d   n1 sB0    Y  ||ksXJ dS )z5Check interaction between global skip and local skip.r%   r)   c                 S   s
   t  d S )Nr   )r   r<   r+   r+   r.   r     s    z9test_skip_nested_validation_and_config_context.<locals>.gr   rX   N)r#   rn   r   )r   r*   Zexpected_skippedr   Zactual_skippedr+   r+   r.   .test_skip_nested_validation_and_config_context  s    

&r   )r   )dnumbersr   r   numpyrT   r`   Zscipy.sparser   Zsklearn._configr   r   Zsklearn.baser   r   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#   Zsklearn.utils.fixesr$   r/   r0   r9   markZparametrizerO   rS   rW   rZ   	TypeErrorr   rd   rj   rm   rn   Zndarrayrq   ru   rx   r   r   r   r   r\   Zfloat32r   callabler   randomZRandomStaterY   rR   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.   <module>   s*  h





	


M






$


"	
	