`L ioddlZddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z m Z ddlZddlmZmZddlmZmZd d lmZGd d eeZd ZdZdZGdde Zej?e dZ!GddeZ"Gdde"Z#Gdde"Z$Gdde"Z%Gdde"Z&Gdde"Z'Gdd e'Z(Gd!d"e"Z)Gd#d$e"Z*Gd%d&e"Z+Gd'd(e"Z,Gd)d*e"Z-Gd+d,e"Z.Gd-d.e"Z/Gd/d0e"Z0Gd1d2e"Z1Gd3d4e"Z2Gd5d6e"Z3Gd7d8Z4d9Z5d:Z6y);N)ABCabstractmethod)Iterable) signature)IntegralReal) csr_matrixissparse)config_context get_config_is_arraylike_not_scalarceZdZdZy)InvalidParameterErrorzyCustom exception to be raised when the parameter of a class/method/function does not have a valid type or value. N__name__ __module__ __qualname____doc__e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/utils/_param_validation.pyrrsrrc |jD]\}}||vr ||}|dk(r|Dcgc] }t|}}|D]}|j|sG|Dcgc]}|jr|}}t |dk(r|d}n3dj |ddDcgc] }t |c}d|d}td|d |d |d |d ycc}wcc}wcc}w) aValidate types and values of given parameters. Parameters ---------- parameter_constraints : dict or {"no_validation"} If "no_validation", validation is skipped for this parameter. If a dict, it must be a dictionary `param_name: list of constraints`. A parameter is valid if it satisfies one of the constraints from the list. Constraints can be: - an Interval object, representing a continuous or discrete range of numbers - the string "array-like" - the string "sparse matrix" - the string "random_state" - callable - None, meaning that None is a valid value for the parameter - any type, meaning that any instance of this type is valid - an Options object, representing a set of elements of a given type - a StrOptions object, representing a set of strings - the string "boolean" - the string "verbose" - the string "cv_object" - the string "nan" - a MissingValues object representing markers for missing values - a HasMethods object, representing method(s) an object must have - a Hidden object, representing a constraint not meant to be exposed to the user params : dict A dictionary `param_name: param_value`. The parameters to validate against the constraints. caller_name : str The name of the estimator or function or method that called this function. no_validationrr, N or zThe z parameter of z must be z. Got instead.)itemsmake_constraintis_satisfied_byhiddenlenjoinstrr) parameter_constraintsparams caller_name param_name param_val constraints constraintconstraints_strcs rvalidate_parameter_constraintsr1sBF"(& I 2 2 +J7 / ) EPQzz2Q Q% J)))4 .9) @Q@Q K;1$%0^$4yy+cr2B!CQ#a&!CDEF#B(* (znN;-@#$F9-yB G&R"DsCC/CC! c6t|tr|dk(r tSt|tr|dk(r tSt|tr|dk(r t S|t ur t S| tSt|tr t|St|tttttfr|St|tr|dk(r tSt|tr|dk(r t!St|tr|dk(r t#St|t$rt'|j(}d|_|St|tr|dk(s%t|t,rt/j0|r t3St5d |) aConvert the constraint into the appropriate Constraint object. Parameters ---------- constraint : object The constraint to convert. Returns ------- constraint : instance of _Constraint The converted constraint. z array-likez sparse matrix random_statebooleanverbose cv_objectTnanUnknown constraint type: ) isinstancer' _ArrayLikes_SparseMatrices _RandomStatescallable _Callables_NoneConstrainttype _InstancesOfInterval StrOptionsOptions HasMethods MissingValues _Booleans_VerboseHelper _CVObjectsHiddenr"r.r$floatnpisnan_NanConstraint ValueErrorr.s rr"r"hsZ*c"z\'A}*c"z_'D  *c"z^'CX|  *d#J''Xz7J N*c"zY'>{*c"zY'>*c"z['@|*f%$Z%:%:;  :s# e(;:u%"((:*> 0 = >>rcfd}|S)aDecorator to validate types and values of functions and methods. Parameters ---------- parameter_constraints : dict A dictionary `param_name: list of constraints`. See the docstring of `validate_parameter_constraints` for a description of the accepted constraints. Note that the *args and **kwargs parameters are not validated and must not be present in the parameter_constraints dictionary. prefer_skip_nested_validation : bool If True, the validation of parameters of inner estimators or functions called by the decorated function will be skipped. This is useful to avoid validating many times the parameters passed by the user from the public facing API. It's also useful to avoid validating parameters that we pass internally to inner functions that are guaranteed to be valid by the test suite. It should be set to True for most functions, except for those that receive non-validated objects as parameters or that are just wrappers around classes because they only perform a partial validation. Returns ------- decorated_function : function or method The decorated function. cbtdtjfd}|S)N_skl_parameter_constraintsctd}|r |i|St }|j|i|}|j|jj Dcgc]2}|j |j|jfvr |j4}}|ddgz }|jjDcic] \}}||vs ||}}}t | j t xs|5 |i|cdddScc}wcc}}w#1swYyxYw#t$r?} t!j"dd jdt%| } t| | d} ~ wwxYw) Nskip_parameter_validationselfcls)r*)rUzparameter of \w+ must bez parameter of z must be)r rbindapply_defaults parametersvalueskindVAR_POSITIONAL VAR_KEYWORDname argumentsr!r1rr rresubr')argskwargsglobal_skip_validationfunc_sigr)p to_ignorekvemsgfuncr(prefer_skip_nested_validations rwrapperz3validate_params..decorator..wrappers%/\2M%N "%T,V,, H#X]]D3F3F  ! ! # ",,33566a.. >>I &% (I'-'7'7'='='?Vtq!1ICUadVFV *%v4;L;L  8#5O9O1  00 11 W11 ) 8 ff/#D$5$5#6h?F ,C0a7 8sH"7D? D D-D&=D D&D#D&#D&& E./:E))E.)setattr functoolswraps)rmror(rns` r decoratorz"validate_params..decorators6 24IJ  ) 8 ) 8Vrr)r(rnrss`` rvalidate_paramsrts>2h rceZdZdZy) RealNotIntzA type that represents reals that are not instances of int. Behaves like float, but also works with values extracted from numpy arrays. isintance(1, RealNotInt) -> False isinstance(1.0, RealNotInt) -> True Nrrrrrvrvsrrvcv|j}|j}|dk(r|S|tk(ry|tk(ry|d|S)z(Convert type into human readable string.builtinsrKint.)rrrr)tmodulequalnames r _type_namer~sF \\F~~H  d hXQxj !!rc6eZdZdZdZedZedZy) _Constraintz&Base class for the constraint objects.cd|_yNF)r$rVs r__init__z_Constraint.__init__s  rcy)aWhether or not a value satisfies the constraint. Parameters ---------- val : object The value to check. Returns ------- is_satisfied : bool Whether or not the constraint is satisfied by this value. NrrVvals rr#z_Constraint.is_satisfied_by rcy)z;A human readable representational string of the constraint.Nrrs r__str__z_Constraint.__str__rrN)rrrrrrr#rrrrrrs40    JJrrc.eZdZdZfdZdZdZxZS)rAz~Constraint representing instances of a given type. Parameters ---------- type : type The valid type. c0t|||_yN)superrr@)rVr@ __class__s rrz_InstancesOf.__init__(s  rc.t||jSrr9r@rs rr#z_InstancesOf.is_satisfied_by,s#tyy))rc2dt|jS)Nzan instance of )r~r@rs rrz_InstancesOf.__str__/s DII!6 9::rrrrrrr#r __classcell__rs@rrArAs*;rrAceZdZdZdZdZy)r?z+Constraint representing the None singleton.c |duSrrrs rr#z_NoneConstraint.is_satisfied_by6s d{rcy)NNonerrs rrz_NoneConstraint.__str__9srNrrrrr#rrrrr?r?3s5rr?ceZdZdZdZdZy)rNz/Constraint representing the indicator `np.nan`.cvt|t xr't|txrtj|Sr)r9rrmathrMrs rr#z_NanConstraint.is_satisfied_by@s.3) ) Wjd.C W SV rcy)Nz numpy.nanrrs rrz_NanConstraint.__str__ErNrrrrrNrN=s9 rrNceZdZdZdZdZy)_PandasNAConstraintz.Constraint representing the indicator `pd.NA`.c ddl}t|t|jxr|j |S#t $rYywxYw)NrF)pandasr9r@NAisna ImportError)rVrpds rr#z#_PandasNAConstraint.is_satisfied_byLs>  c4;/@BGGCL @  s58 AAcy)Nz pandas.NArrs rrz_PandasNAConstraint.__str__TrrNrrrrrrIs8rrc:eZdZdZddfd ZdZdZdZxZS)rDaGConstraint representing a finite set of instances of a given type. Parameters ---------- type : type options : set The set of valid scalars. deprecated : set or None, default=None A subset of the `options` to mark as deprecated in the string representation of the constraint. N deprecatedct|||_||_|xs t |_|j |jz r t dy)Nz7The deprecated options must be a subset of the options.)rrr@optionssetrrO)rVr@rrrs rrzOptions.__init__gsK   $- ??T\\ )VW W *rcNt||jxr||jvSr)r9r@rrs rr#zOptions.is_satisfied_byps!#tyy)AcT\\.AArc2|}||jvr|d}|S)z-Add a deprecated mark to an option if needed.z (deprecated)r)rVoption option_strs r_mark_if_deprecatedzOptions._mark_if_deprecatedss'z T__ $&<}5Jrcdj|jDcgc]}|j|c}}dt|jd|dScc}w)Nrza z among {})r&rrr~r@)rVo options_strs rrzOptions.__str__zsWyyt||L!$2215LMN Jtyy)*)K=CCMsA) rrrrrr#rrrrs@rrDrDXs$ 59XBDrrDc(eZdZdZddfd ZxZS)rCa2Constraint representing a finite set of strings. Parameters ---------- options : set of str The set of valid strings. deprecated : set of str or None, default=None A subset of the `options` to mark as deprecated in the string representation of the constraint. Nrc2t|t||y)N)r@rr)rrr')rVrrrs rrzStrOptions.__init__s c7zJr)rrrrrrrs@rrCrCs /3KKrrCc:eZdZdZfdZdZdZdZdZxZ S)rBuMConstraint representing a typed interval. Parameters ---------- type : {numbers.Integral, numbers.Real, RealNotInt} The set of numbers in which to set the interval. If RealNotInt, only reals that don't have the integer type are allowed. For example 1.0 is allowed but 1 is not. left : float or int or None The left bound of the interval. None means left bound is -∞. right : float, int or None The right bound of the interval. None means right bound is +∞. closed : {"left", "right", "both", "neither"} Whether the interval is open or closed. Possible choices are: - `"left"`: the interval is closed on the left and open on the right. It is equivalent to the interval `[ left, right )`. - `"right"`: the interval is closed on the right and open on the left. It is equivalent to the interval `( left, right ]`. - `"both"`: the interval is closed. It is equivalent to the interval `[ left, right ]`. - `"neither"`: the interval is open. It is equivalent to the interval `( left, right )`. Notes ----- Setting a bound to `None` and setting the interval closed is valid. For instance, strictly speaking, `Interval(Real, 0, None, closed="both")` corresponds to `[0, +∞) U {+∞}`. czt|||_||_||_||_|j yr)rrr@leftrightclosed _check_params)rVr@rrrrs rrzInterval.__init__s6      rc|jtttfvrt d|jd|j dvrt d|j d|jturd}|j (t|j tstd||j(t|jtstd||j )|j dvrt d |j d ||j|j d vr}t d |j d ||j %t|j ts td |j%t|jts td|jL|j ?|j|j kr%t d|j d|jyyy)NzFtype must be either numbers.Integral, numbers.Real or RealNotInt. Got r )rrbothneitherz@closed must be either 'left', 'right', 'both' or 'neither'. Got z"for an interval over the integers.zExpecting left to be an int zExpecting right to be an int rrz"left can't be None when closed ==  rrz#right can't be None when closed == z#Expecting left to be a real number.z$Expecting right to be a real number.z(right can't be less than left. Got left=z and right=) r@rrrvrOrrr9 TypeErrorr)rVsuffixs rrzInterval._check_paramss 99XtZ8 8 {)-  ;;B B{{m9.  99 9Fyy$Z 8-L">vh GHHzz%jX.N"?x HIIyy T[[4D%D 8 QvhOzz!dkk5F&F 9$++axPyy$Z 4-H EFFzz%jT.J FGG :: !dii&; dii@W:499+F & AX&; !rct|tstj|ry|jdvrt j nt j}|jdvrt jnt j}|jtj n |j}|jtjn |j}|||ry|||ryy)NFrrT) r9rrLrMroperatorltlegtgerinfr)rVrleft_cmp right_cmprrs r __contains__zInterval.__contains__s#x(RXXc]"&++1A"A8;;x{{#';;2C#CHKK ))+w**,$** C  S% rc8t||jsy||vSrrrs rr#zInterval.is_satisfied_bys#tyy)d{rc|jturdnd}|jdvrdnd}|jdn |j}|jdn |j}|jdvrd nd }|jtk(s%t |jt r t|}|jtk(s%t |jt r t|}|d ||d ||S) Nzan intza floatr[(z-infrr])z in the range r)r@rrrrr9rrK)rVtype_str left_bracket left_bound right_bound right_brackets rrzInterval.__str__s#yyH48)"kk-==s3 #yy0Vdii #zz1etzz #{{.??S yyH$DIIt)Dz*JyyH$DJJ)E ,KjnZL;-  H r) rrrrrrrr#rrrs@rrBrBs#!F%N   rrBceZdZdZdZdZy)r:z#Constraint representing array-likesct|Srrrs rr#z_ArrayLikes.is_satisfied_bys ',,rcy)Nz an array-likerrs rrz_ArrayLikes.__str__srNrrrrr:r:s--rr:ceZdZdZdZdZy)r;z(Constraint representing sparse matrices.ct|Sr)r rs rr#z_SparseMatrices.is_satisfied_by }rcy)Nza sparse matrixrrs rrz_SparseMatrices.__str__s rNrrrrr;r;s2!rr;ceZdZdZdZdZy)r>z"Constraint representing callables.ct|Sr)r=rs rr#z_Callables.is_satisfied_by&rrcy)Nz a callablerrs rrz_Callables.__str__)srNrrrrr>r>#s,rr>c.eZdZdZfdZdZdZxZS)r<zConstraint representing random states. Convenience class for [Interval(Integral, 0, 2**32 - 1, closed="both"), np.random.RandomState, None] ct|ttdddt t j jtg|_ y)Nrlrr) rrrBrrArLrandom RandomStater? _constraintsrVrs rrz_RandomStates.__init__4s>  Xq)F ; .. /   rc@tfd|jDS)Nc3@K|]}|jywrr#.0r0rs r z0_RandomStates.is_satisfied_by..=Ea1$$S)Eanyrrs `rr#z_RandomStates.is_satisfied_by<E43D3DEEErcdj|jddDcgc] }t|c}d|jdScc}wNrrrr&rr'rVr0s rrz_RandomStates.__str__?Qyy$*;*;CR*@AQ#a&ABCD!!"%& ( AArrs@rr<r<-  F rr<c.eZdZdZfdZdZdZxZS)rGz[Constraint representing boolean likes. Convenience class for [bool, np.bool_] c|t|ttttj g|_yr)rrrAboolrLbool_rrs rrz_Booleans.__init__Ms,     " rc@tfd|jDS)Nc3@K|]}|jywrrrs rrz,_Booleans.is_satisfied_by..Urrrrs `rr#z_Booleans.is_satisfied_byTrrcdj|jddDcgc] }t|c}d|jdScc}wrrrs rrz_Booleans.__str__Wrrrrs@rrGrGFs  F rrGc.eZdZdZfdZdZdZxZS)rHzHelper constraint for the verbose parameter. Convenience class for [Interval(Integral, 0, None, closed="left"), bool, numpy.bool_] ct|ttdddt t t t jg|_y)Nrrr) rrrBrrArrLrrrs rrz_VerboseHelper.__init__es:  Xq$v 6    " rc@tfd|jDS)Nc3@K|]}|jywrrrs rrz1_VerboseHelper.is_satisfied_by..nrrrrs `rr#z_VerboseHelper.is_satisfied_bymrrcdj|jddDcgc] }t|c}d|jdScc}wrrrs rrz_VerboseHelper.__str__prrrrs@rrHrH^rrrHc0eZdZdZdfd ZdZdZxZS)rFaHelper constraint for the `missing_values` parameters. Convenience for [ Integral, Interval(Real, None, None, closed="both"), str, # when numeric_only is False None, # when numeric_only is False _NanConstraint(), _PandasNAConstraint(), ] Parameters ---------- numeric_only : bool, default=False Whether to consider only numeric missing value markers. c t|||_ttt t dddttg|_ |js3|jjtttgyy)Nrr) rr numeric_onlyrArrBrrNrrextendr'r?)rVrrs rrzMissingValues.__init__su (  " T4f 5    !       $ $l3&79J%K L!rc@tfd|jDS)Nc3@K|]}|jywrrrs rrz0MissingValues.is_satisfied_by..rrrrs `rr#zMissingValues.is_satisfied_byrrcdj|jddDcgc] }t|c}d|jdScc}wrrrs rrzMissingValues.__str__rr)Frrs@rrFrFws& MF rrFcPeZdZdZedeegidfdZdZdZ xZ S)rEaIConstraint representing objects that expose specific methods. It is useful for parameters following a protocol and where we don't want to impose an affiliation to a specific module or class. Parameters ---------- methods : str or list of str The method(s) that the object is expected to expose. methodsT)rncVt|t|tr|g}||_yr)rrr9r'r)rVrrs rrzHasMethods.__init__s(  gs #iG rc@tfd|jDS)Nc3JK|]}tt|dywr)r=getattr)rmethodrs rrz-HasMethods.is_satisfied_by..sSF8GC67Ss #)allrrs `rr#zHasMethods.is_satisfied_bysSdllSSSrct|jdk(r|jd}nGdj|jddDcgc] }t|c}d|jd}d|Scc}w)Nrrrrz and zan object implementing )r%rr&repr)rVrms rrzHasMethods.__str__s t||  !a+G99t||CR/@A!d1gABCDLL$') ) 22BsA6) rrrrrtr'listrr#rrrs@rrErEs;  S$K &*  T3rrEceZdZdZdZdZy)_IterablesNotStringz7Constraint representing iterables that are not strings.cHt|txrt|t Sr)r9rr'rs rr#z#_IterablesNotString.is_satisfied_bys#x(EC1E-EErcy)Nz an iterablerrs rrz_IterablesNotString.__str__srNrrrrr r sAFrr c.eZdZdZfdZdZdZxZS)rIzConstraint representing cv objects. Convenient class for [ Interval(Integral, 2, None, closed="left"), HasMethods(["split", "get_n_splits"]), _IterablesNotString(), None, ] ct|ttdddt ddgt t g|_y)Nr rrsplit get_n_splits)rrrBrrEr r?rrs rrz_CVObjects.__init__s?  Xq$v 6 0 1  !    rc@tfd|jDS)Nc3@K|]}|jywrrrs rrz-_CVObjects.is_satisfied_by..rrrrs `rr#z_CVObjects.is_satisfied_byrrcdj|jddDcgc] }t|c}d|jdScc}wrrrs rrz_CVObjects.__str__rrrrs@rrIrIs  F rrIceZdZdZdZy)rJzClass encapsulating a constraint not meant to be exposed to the user. Parameters ---------- constraint : str or _Constraint instance The constraint to be used internally. c||_yrrP)rVr.s rrzHidden.__init__s $rN)rrrrrrrrrJrJs %rrJctt|trddj|jSt|trt j gdSt|tryt|trtddiSt|tryt|tryt|trN|jtur<|j|jd z S|j|jd zSt t|tr|jt"t$fvr|j|jd z S|j|jd zS|j&d vrt j( S|j&d vrt j(St j*St ) aReturn a value that does not satisfy the constraint. Raises a NotImplementedError if there exists no invalid value for this constraint. This is only useful for testing purpose. Parameters ---------- constraint : _Constraint instance The constraint to generate a value for. Returns ------- val : object A value that does not satisfy the constraint. znot rrr r HasNotMethodsrza stringznot a cv objectrgư>)rr)rr)r9rCr&rrFrLarrayrHrEr@r rIrBrrrNotImplementedErrorrrvrrr7rPs rgenerate_invalid_param_valr2sr"*j)fkk*"4"45677*m,xx ""*n-*j),tOR,..*12*j) *h'JOOx,G ?? &??Q& &    '##a' '"!*h'JOOj?Q,Q ?? &??T) )    '##d* *    4 4FF7N    3 366Mvv rc Rt|trtjgdSt|trt ddgddggSt|t rtjjdSt|trdSt|tryt|tr\|jtjurtjgdS|jttfvry|jSt|t ryt|t"ryt|t$r|j&rtj(St|t$r |j&syt|t*r,td d |j,Dcic]}|d c}St|t.rgdSt|t0ry t|t2r|j4D]}|cSt|t6r|}|j8 |j:y|j8|j:dz S|j:|j8dzS|jtur|j8|j:zd z S|j8dzSt=d|cc}w)a1Return a value that does satisfy a constraint. This is only useful for testing purpose. Parameters ---------- constraint : Constraint instance The constraint to generate a value for. Returns ------- val : object A value that does satisfy the constraint. r-rr*c|Srr)xs rz&generate_valid_param..UsrNTmissingValidHasMethodsrcyrrrs rr7z&generate_valid_param..srrr r8)r9r:rLr0r;r r<rrr>r?rAr@ndarrayrrrGrHrFrr7rErr rIrDrrBrrrO)r.rrintervals rgenerate_valid_paramr><s6*k*xx ""*o.Aq6Aq6*++*m,yy$$R((*j)*o.*l+ ??bjj (88I& & ??x. .  *i(*n-*m,1H1Hvv *m,Z5L5L*j) t r*BTBT#UQA'8$8#U   *12*j)*g& (( FM *h' == X^^%; ]] ">>A% % ^^ #==1$ $}}$ 6!;;}}q(( 0 = >>7$Vs J$)7rqrrraabcrrcollections.abcrinspectrnumbersrrnumpyrL scipy.sparser r _configr r validationrrOrrr1r"rtrvregisterrKr~rrAr?rNrrDrCrBr:r;r>r<rGrHrFrEr rIrJr2r>rrrrHsh  #$"-00J IX+?\Sl E "J#J4;;;(k [  + &Dk&DRKK"z {z z+!k! K 2  0 [ 2* K* Z!3!3H+  > % %;|R?r