o
    \iW_                     @   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ejKe!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      dS )z/A function to test the validation of functions.N )r%   r&   r'   r(   argskwargsr,   r,   /var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/lib/python3.10/site-packages/sklearn/utils/tests/test_param_validation.py_func)       r0   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   r+   )zA validated methodNr,   selfr%   r,   r,   r/   _method4   r1   z_Class._methodc                 C   r+   )zA deprecated validated methodNr,   r3   r,   r,   r/   _deprecated_method8   r1   z_Class._deprecated_methodN)	__name__
__module____qualname____doc__r#   r   r5   r   r6   r,   r,   r,   r/   r2   1   s    
r2   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%   r3   r,   r,   r/   __init__C   s   
z_Estimator.__init__Tr)   Nc                 C      d S r=   r,   r4   Xyr,   r,   r/   fitF      z_Estimator.fitNN)r7   r8   r9   r:   r   r<   dict__annotations__r?   r   rD   r,   r,   r,   r/   r;   >   s   
 r;   interval_typec                 C   s   t | dddd}d|v sJ d|vsJ t | dddd}d|vs"J d|v s(J t | dddd}d|v s6J d|v s<J t | dddd}d|vsJJ d|vsPJ dS )	z.Check the range of values depending on closed.   leftclosedrightbothneitherN)r   rI   intervalr,   r,   r/   test_interval_rangeK   s   rT   c                 C   s   t | dddd}dd |vsJ dd |vsJ tdd |vs"J tdd |vs,J t | ddd dd}dd |v s>J dd |vsFJ tdd |v sPJ tdd |vsZJ dd |vsbJ dS )	zbCheck that Interval constraint work with large integers.

    non-regression test for #26648.
    r   rK   rQ   rM   A      i   N)r   floatrR   r,   r,   r/   test_interval_large_integers_   s   rX   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s6J dS )zjCheck that inf is included iff a bound is closed and set to None.

    Only valid for real intervals.
    r   NrO   rM   rL   rQ   )r   r   npinfrS   r,   r,   r/   test_interval_inf_in_boundst   s   r\   rS      rL   rM   rP   c                 C   s   t j| vsJ dS )z)Check that np.nan is not in any interval.N)rY   nanr[   r,   r,   r/   test_nan_not_in_interval   s   r_   zparams, error, match      ?rK   )typerL   rO   rN   z=Expecting left to be an int for an interval over the integersg       @rQ   z>Expecting right to be an int for an interval over the integersz&left can't be None when closed == leftrO   z(right can't be None when closed == rightzright can't be less than leftc                 C   sB   t j||d tdi |  W d   dS 1 sw   Y  dS )zNCheck that informative errors are raised for invalid combination of parametersmatchNr,   )pytestraisesr   )paramserrorrd   r,   r,   r/   test_interval_errors   s    "ri   c                  C   sP   t h ddhd} | dsJ | dsJ | drJ dt| v s&J 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
   ro   c                  C   sX   t tddtjhdhd} | dsJ | tjsJ | dr"J dt| v s*J dS )z'Sanity check for the Options constraintg            ?r
   Gz?z-0.5 (deprecated)N)r   r   rY   rZ   rk   rl   rm   r,   r,   r/   test_options   s
   rr   ztype, expected_type_nameintrW   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   rl   )ra   expected_type_name
constraintr,   r,   r/   %test_instances_of_type_human_readable   s   rw   c                  C   s\   t ddg} G dd d}G dd d}| | sJ | | r$J t| dks,J 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   r@   r=   r,   r4   r,   r,   r/   r%         z test_hasmethods.<locals>._Good.ac                 S   r@   r=   r,   rx   r,   r,   r/   r&      ry   z test_hasmethods.<locals>._Good.bN)r7   r8   r9   r%   r&   r,   r,   r,   r/   _Good   s    rz   c                   @   s   e Zd Zdd ZdS )ztest_hasmethods.<locals>._Badc                 S   r@   r=   r,   rx   r,   r,   r/   r%      ry   ztest_hasmethods.<locals>._Bad.aN)r7   r8   r9   r%   r,   r,   r,   r/   _Bad   s    r{   z"an object implementing 'a' and 'b'N)r   rk   rl   )rv   rz   r{   r,   r,   r/   test_hasmethods   s   r|   rv   rj   )numeric_onlyrD   c                 C   s   t | }| |rJ dS )z>Check that the value generated does not satisfy the constraintNr    rk   )rv   	bad_valuer,   r,   r/   test_generate_invalid_param_val   s   r   zinteger_interval, real_interval         i   
   c                 C   sP   t |d}||rJ | |rJ t | d}||rJ | |r&J dS )ztCheck that the value generated for an interval constraint does not satisfy any of
    the interval constraints.
    rv   Nr~   )integer_intervalreal_intervalr   r,   r,   r/   +test_generate_invalid_param_val_2_intervals   s   
Q
r   c                 C   s8   t t t|  W d   dS 1 sw   Y  dS )zmCheck that the function raises NotImplementedError when there's no invalid value
    for the constraint.
    N)re   rf   NotImplementedErrorr    r   r,   r,   r/   )test_generate_invalid_param_val_all_validW  s   
"r   >   r]   rK   r   c                 C   s   t | }| |sJ dS )z;Check that the value generated does satisfy the constraint.N)r!   rk   )rv   valuer,   r,   r/   test_generate_valid_paraml  s   r   zconstraint_declaration, valuegzG?*   r&   c                 C   s   | d S )Nr]   r,   )xr,   r,   r/   <lambda>  s    r   rF   z
array-likesparse matrixc                 C   s$   g | ]}d |ddgddggfqS )r   r]   rK   r   r   r,   ).0	containerr,   r,   r/   
<listcomp>  s    r   )random_stater   r   )r   Nrp   )booleanF)verboser]   r^   g      i  missingr>   )	cv_objectr   c                 C   s   t | }||sJ dS )z+Sanity check for the is_satisfied_by methodN)r"   rk   )constraint_declarationr   rv   r,   r,   r/   test_is_satisfied_by  s   &r   z1constraint_declaration, expected_constraint_classoption1option2rq   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   expected_constraint_classrv   r,   r,   r/   test_make_constraint  s   r   c                   C   s<   t jtdd td W d   dS 1 sw   Y  dS )zNCheck that an informative error is raised when an unknown constraint is passedzUnknown constraintrc   znot a valid constraintN)re   rf   
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 sw   Y  t jtdd tddgddi W d   n1 s8w   Y  t jtd	d tdi ddi W d   n1 sXw   Y  t jtd
d tdddd W d   n1 svw   Y  t jtdd tdgg dR ddiddi W d   n1 sw   Y  t jtd	d tdgg dR ddiddi W d   dS 1 sw   Y  dS )zGCheck that validate_params works no matter how the arguments are passedz"The 'a' parameter of _func must berc   wrongr]   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   rK   r   r   er   r]   rK   r   four)r]   )re   rf   r   r0   r,   r,   r,   r/   test_validate_params  s<   $$"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   r@   r=   r,   )r%   r&   r,   r,   r/   func  rE   z1test_validate_params_missing_params.<locals>.funcr]   rK   N)r#   rs   )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w   Y  tjtdd/ tjtdd | ddd	d W d   n1 sDw   Y  W d   dS W d   dS 1 s\w   Y  dS )
z5Check that validate_params functions can be decoratedzFunction _func is deprecatedrc   r]   rK   r   r   Nr   r   )r   r0   re   warnsFutureWarningrf   r   )decorated_functionr,   r,   r/    test_decorate_validated_function  s   
"r   c                	   C   s   t jtdd t d W d   n1 sw   Y  t jtdd. t jtdd t d W d   n1 s=w   Y  W d   dS W d   dS 1 sUw   Y  dS )z-Check that validate_params works with methodsz+The 'a' parameter of _Class._method must berc   r   Nz)Function _deprecated_method is deprecatedz6The 'a' parameter of _Class._deprecated_method must be)re   rf   r   r2   r5   r   r   r6   r,   r,   r,   r/   test_validate_params_method  s   "r   c                  C   sD   t d} tjtdd |   W d   dS 1 sw   Y  dS )z9Check that validate_params works with Estimator instancesr   z'The 'a' parameter of _Estimator must berc   N)r;   re   rf   r   rD   )estr,   r,   r/   test_validate_params_estimator%  s   
"r   c                   C   sH   t jtdd th dddhd W d   dS 1 sw   Y  dS )z@Check that the deprecated parameter must be a subset of options.z#deprecated options must be a subsetrc   rj   r%   r(   r
   N)re   rf   r   r   r,   r,   r,   r/   !test_stroptions_deprecated_subset0  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 s5w   Y  t|j}d|v sEJ d|vsKJ dS )zECheck that internal constraints are not exposed in the error message.paramTr)   c                 S   r@   r=   r,   r   r,   r,   r/   f9  s   z!test_hidden_constraint.<locals>.fr]   rK   r   )r%   r&   r'   r   The 'param' parameterrc   badr   Nzan instance of 'dict'zan instance of 'list')	r#   r   listrG   re   rf   r   rl   r   r   exc_infoerr_msgr,   r,   r/   test_hidden_constraint6  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 s5w   Y  t|j}d|v sEJ d|vsKJ dS )zBCheck that we can have 2 StrOptions constraints, one being hidden.r   autowarnTr)   c                 S   r@   r=   r,   r   r,   r,   r/   r   Q     z!test_hidden_stroptions.<locals>.fr   rc   r   r   N)r#   r   r   re   rf   r   rl   r   r   r,   r,   r/   test_hidden_stroptionsN  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.
    _skl_parameter_constraintsN)hasattrr0   r2   r5   r,   r,   r,   r/   4test_validate_params_set_param_constraints_attributeg  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   r@   r=   r,   r   r,   r,   r/   r   t  rE   z1test_boolean_constraint_deprecated_int.<locals>.fFN)r#   rY   bool_r   r,   r,   r/   &test_boolean_constraint_deprecated_into  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 s'w   Y  G dd d}| |d | | d dS )z5Check that validation can be skipped for a parameter.Nno_validationparam1param2Tr)   c                 S   r@   r=   r,   r   r,   r,   r/   r     r   ztest_no_validation.<locals>.fzThe 'param1' parameterrc   r   )r   c                   @   s   e Zd ZdS )z$test_no_validation.<locals>.SomeTypeN)r7   r8   r9   r,   r,   r,   r/   SomeType  s    r   )r   rF   r#   rs   re   rf   r   )r   r   r,   r,   r/   test_no_validation}  s   
r   c                  C   s<   t d} t }|| jsJ |tg drJ dS )z9Add a specific test for checking support for `pandas.NA`.pandasr   N)re   importorskipr   rk   NArY   array)pd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rJ dS )zGCheck that a string does not satisfy the _IterableNotString constraint.r   r   zsome stringN)r   rk   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s'J | ds.J | dr5J dS )zUCheck that the _CVObjects constraint accepts all current ways
    to pass cv objects.r   r]   rK   r   r   Nznot a CV object)r   rk   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?   )r4   r&   r   r,   r/   r?     s   z@test_third_party_estimator.<locals>.ThirdPartyEstimator.__init__Nc                    s   t  || d S r=   )r   rD   rA   r   r,   r/   rD     s   z;test_third_party_estimator.<locals>.ThirdPartyEstimator.fitrF   )r7   r8   r9   r?   rD   __classcell__r,   r,   r   r/   ThirdPartyEstimator  s    r   r   r&   N)r;   rD   )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   r]   rP   rM   r`   N)r   r   rk   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sJ t tdtr"J dS )zCheck for the RealNotInt type.r`   r]   N)
isinstancer   rY   float64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 s$w   Y  tdd | dd	 W d
   d
S 1 s?w   Y  d
S )z@Check that param validation can be skipped using config_context.r%   Tr)   c                 S   r@   r=   r,   r>   r,   r,   r/   r     rE   z%test_skip_param_validation.<locals>.fThe 'a' parameterrc   1r>   Nskip_parameter_validation)r#   rs   re   rf   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 s3w   Y  | rA|dd dS tjtdd
 |dd W d   dS 1 sYw   Y  dS )z,Check that nested validation can be skipped.r%   Tr)   c                 S   r@   r=   r,   r>   r,   r,   r/   r     rE   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' parameterrc   r   r   Nr]   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 s!w   Y  ||ks,J 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   r]   N)r#   rs   r   )r   r*   expected_skippedr   actual_skippedr,   r,   r/   .test_skip_nested_validation_and_config_context  s   


r   )r   )dnumbersr   r   numpyrY   re   scipy.sparser   sklearn._configr   r   sklearn.baser   r   sklearn.model_selectionr	   sklearn.utilsr   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#   sklearn.utils.fixesr$   r0   r2   r;   markparametrizerT   rX   r\   r_   	TypeErrorr   ri   ro   rr   rs   ndarrayrw   r|   r   r   r   r   r   ra   float32r   callabler   randomRandomStater^   rW   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






$

"	
	