
    0PhVo                     ,   d dl Z d dlZd dlZd dl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 d dlZd dlmZmZ ddlmZmZ d	d
lmZ  G d dee          Zd Zd Zd Z G d de          Ze                    e            d Z! G d de          Z" G d de"          Z# G d de"          Z$ G d de"          Z% G d de"          Z& G d de"          Z' G d d e'          Z( G d! d"e"          Z) G d# d$e"          Z* G d% d&e"          Z+ G d' d(e"          Z, G d) d*e"          Z- G d+ d,e"          Z. G d- d.e"          Z/ G d/ d0e"          Z0 G d1 d2e"          Z1 G d3 d4e"          Z2 G d5 d6e"          Z3 G d7 d8          Z4d9 Z5d: Z6dS );    N)ABCabstractmethod)Iterable)	signature)IntegralReal)
csr_matrixissparse   )config_context
get_config   _is_arraylike_not_scalarc                       e Zd ZdZdS )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__     _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/utils/_param_validation.pyr   r      s           r   r   c                    |                                 D ]\  }}|| vr
| |         }|dk    rd |D             }|D ]}|                    |          r nxd |D             }t          |          dk    r
|d          }n2d                    d |dd	         D                        d
|d	          }t	          d|d| d| d|d	          dS )a  Validate 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_validationc                 ,    g | ]}t          |          S r   )make_constraint.0
constraints     r   
<listcomp>z2validate_parameter_constraints.<locals>.<listcomp>K   s     QQQzz22QQQr   c                      g | ]}|j         	|S r   hiddenr   s     r   r"   z2validate_parameter_constraints.<locals>.<listcomp>V   s0       )
@Q  r   r   r   , c                 ,    g | ]}t          |          S r   strr    cs     r   r"   z2validate_parameter_constraints.<locals>.<listcomp>^   s    !C!C!CQ#a&&!C!C!Cr   N or zThe z parameter of z	 must be z. Got 	 instead.)itemsis_satisfied_bylenjoinr   )parameter_constraintsparamscaller_name
param_name	param_valconstraintsr!   constraints_strs           r   validate_parameter_constraintsr:      s   F "( & &
I 222+J7/))QQ[QQQ% 	 	J)))44  -8  K ;1$$%0^"5 yy!C!C+crc2B!C!C!CDD * *#B* *  
 (Bz B B; B B#B B+4B B B  % #& &r   c                    t          | t                    r| dk    rt                      S t          | t                    r| dk    rt                      S t          | t                    r| dk    rt	                      S | t
          u rt                      S | t                      S t          | t                    rt          |           S t          | t          t          t          t          t          f          r| S t          | t                    r| dk    rt                      S t          | t                    r| dk    rt!                      S t          | t                    r| dk    rt#                      S t          | t$                    rt'          | j                  } d| _        | S t          | t                    r| d	k    rt-                      S t/          d
|            )a  Convert 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_stateNbooleanverbose	cv_objectTnanUnknown constraint type: )
isinstancer)   _ArrayLikes_SparseMatrices_RandomStatescallable
_Callables_NoneConstrainttype_InstancesOfInterval
StrOptionsOptions
HasMethodsMissingValues	_Booleans_VerboseHelper
_CVObjectsHiddenr   r!   r%   _NanConstraint
ValueErrorr!   s    r   r   r   h   s    *c"" z\'A'A}}*c"" !z_'D'D   *c"" z^'C'CX||   *d## (J'''Xz7JN   *c"" zY'>'>{{*c""  zY'>'>*c"" z['@'@||*f%% $Z%:;;
 
*c""  zU':':
===
>
>>r   c                      fd}|S )a  Decorator 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.
    c                 n     t           d           t          j                    fd            }|S )N_skl_parameter_constraintsc                  t   t                      d         }|r | i |S t                    } |j        | i |}|                                 d |j                                        D             ddgz  fd|j                                        D             }t          	|j	                   	 t          
p|          5   | i |cd d d            S # 1 swxY w Y   d S # t          $ rA}t          j        dd	j	         d
t          |                    }t          |          |d }~ww xY w)Nskip_parameter_validationc                 F    g | ]}|j         |j        |j        fv |j        S r   )kindVAR_POSITIONALVAR_KEYWORDname)r    ps     r   r"   zGvalidate_params.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>   s;       6a.>>> >>>r   selfclsc                 $    i | ]\  }}|v	||S r   r   )r    kv	to_ignores      r   
<dictcomp>zGvalidate_params.<locals>.decorator.<locals>.wrapper.<locals>.<dictcomp>   s)    VVVtq!1ICUCUaCUCUCUr   )r5   )r[   zparameter of \w+ must bezparameter of z must be)r   r   bindapply_defaults
parametersvalues	argumentsr/   r:   r   r   r   resubr)   )argskwargsglobal_skip_validationfunc_sigr4   emsgrg   funcr3   prefer_skip_nested_validations          @r   wrapperz3validate_params.<locals>.decorator.<locals>.wrapper   s   %/\\2M%N"% -tT,V,,, H #X]D3F33F!!### !,3355  I
 &%(IVVVVv'7'='='?'?VVVF*%v4;L   8#5O9O   1 1
  40001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ) 
8 
8 
8
 f/?D$5???FF 
 ,C00a7
8s<   8C, 
CC, C##C, &C#'C, ,
D76<D22D7)setattr	functoolswraps)rv   rx   r3   rw   s   ` r   	decoratorz"validate_params.<locals>.decorator   sZ     	24IJJJ			)	8 )	8 )	8 )	8 )	8 )	8 
	)	8V r   r   )r3   rw   r|   s   `` r   validate_paramsr}      s+    >2 2 2 2 2 2h r   c                       e Zd ZdZdS )
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
    Nr   r   r   r   r   r      s           r   r   c                 p    | j         }| j        }|dk    r|S | t          k    rdS | t          k    rdS | d| S )z(Convert type into human readable string.builtinsfloatint.)r   r   r   r   )tmodulequalnames      r   
_type_namer      sP    \F~H	
dw	
hu!!x!!!r   c                   D    e Zd ZdZd Zed             Zed             ZdS )_Constraintz&Base class for the constraint objects.c                     d| _         d S NFr$   rb   s    r   __init__z_Constraint.__init__  s    r   c                     dS )a  Whether 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.
        Nr   rb   vals     r   r0   z_Constraint.is_satisfied_by	        r   c                     dS )z;A human readable representational string of the constraint.Nr   r   s    r   __str__z_Constraint.__str__  r   r   N)r   r   r   r   r   r   r0   r   r   r   r   r   r     sd        00     ^ J J ^J J Jr   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )rJ   z~Constraint representing instances of a given type.

    Parameters
    ----------
    type : type
        The valid type.
    c                 V    t                                                       || _        d S N)superr   rI   )rb   rI   	__class__s     r   r   z_InstancesOf.__init__&  s$    			r   c                 ,    t          || j                  S r   rB   rI   r   s     r   r0   z_InstancesOf.is_satisfied_by*  s    #ty)))r   c                 0    dt          | j                  S )Nzan instance of )r   rI   r   s    r   r   z_InstancesOf.__str__-  s    :DI!6!6:::r   r   r   r   r   r   r0   r   __classcell__r   s   @r   rJ   rJ     s`             * * *; ; ; ; ; ; ;r   rJ   c                       e Zd ZdZd Zd ZdS )rH   z+Constraint representing the None singleton.c                 
    |d u S r   r   r   s     r   r0   z_NoneConstraint.is_satisfied_by4  s    d{r   c                     dS )NNoner   r   s    r   r   z_NoneConstraint.__str__7  s    vr   Nr   r   r   r   r0   r   r   r   r   rH   rH   1  s8        55      r   rH   c                       e Zd ZdZd Zd ZdS )rT   z/Constraint representing the indicator `np.nan`.c                     t          |t                     o(t          |t                    ot          j        |          S r   )rB   r   r   mathisnanr   s     r   r0   z_NanConstraint.is_satisfied_by>  s4    3)))Wjd.C.CW
SV	
r   c                     dS )Nz	numpy.nanr   r   s    r   r   z_NanConstraint.__str__C      {r   Nr   r   r   r   rT   rT   ;  s8        99
 
 

    r   rT   c                       e Zd ZdZd Zd ZdS )_PandasNAConstraintz.Constraint representing the indicator `pd.NA`.c                     	 dd l }t          |t          |j                            o|                    |          S # t
          $ r Y dS w xY w)Nr   F)pandasrB   rI   NAisnaImportError)rb   r   pds      r   r0   z#_PandasNAConstraint.is_satisfied_byJ  s\    	c4;;//@BGGCLL@ 	 	 	55	s   := 
A
Ac                     dS )Nz	pandas.NAr   r   s    r   r   z_PandasNAConstraint.__str__R  r   r   Nr   r   r   r   r   r   G  s8        88      r   r   c                   :     e Zd ZdZdd fd
Zd Zd Zd Z xZS )rM   aG  Constraint 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
deprecatedc                    t                                                       || _        || _        |pt	                      | _        | j        | j        z
  rt          d          d S )Nz7The deprecated options must be a subset of the options.)r   r   rI   optionssetr   rU   )rb   rI   r   r   r   s       r   r   zOptions.__init__e  sd    	$-?T\) 	XVWWW	X 	Xr   c                 >    t          || j                  o|| j        v S r   )rB   rI   r   r   s     r   r0   zOptions.is_satisfied_byn  s     #ty))AcT\.AAr   c                 (    |}|| j         v r| d}|S )z-Add a deprecated mark to an option if needed.z (deprecated)r   )rb   option
option_strs      r   _mark_if_deprecatedzOptions._mark_if_deprecatedq  s*    ]
T_$$&555Jr   c                      d                      fd j        D                        }dt           j                   d| dS )Nr&   c                 :    g | ]}                     |          S r   )r   )r    orb   s     r   r"   z#Options.__str__.<locals>.<listcomp>z  s'    LLL!$22155LLLr   za z among {})r2   r   r   rI   )rb   options_strs   ` r   r   zOptions.__str__x  sW    yyLLLLt|LLLMMO 	 DJty))CCKCCCCr   )	r   r   r   r   r   r0   r   r   r   r   s   @r   rM   rM   V  s          59 X X X X X X XB B B  D D D D D D Dr   rM   c                   (     e Zd ZdZdd fd
Z xZS )rL   a2  Constraint 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.
    Nr   c                Z    t                                          t          ||           d S )N)rI   r   r   )r   r   r)   )rb   r   r   r   s      r   r   zStrOptions.__init__  s(    c7zJJJJJr   )r   r   r   r   r   r   r   s   @r   rL   rL     s\        
 
 /3 K K K K K K K K K K Kr   rL   c                   :     e Zd ZdZ fdZd Zd Zd Zd Z xZ	S )rK   uM  Constraint 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 {+∞}`.
    c                    t                                                       || _        || _        || _        || _        |                                  d S r   )r   r   rI   leftrightclosed_check_params)rb   rI   r   r   r   r   s        r   r   zInterval.__init__  sM    		
r   c                    | j         t          t          t          fvrt	          d| j          d          | j        dvrt	          d| j         d          | j         t          u rd}| j        ,t          | j        t                    st          d|           | j	        ,t          | j	        t                    st          d|           | j        #| j        dv rt	          d	| j         d
|           | j	        #| j        dv rt	          d| j         d
|           n`| j        )t          | j        t                    st          d          | j	        )t          | j	        t                    st          d          | j	        6| j        1| j	        | j        k    r#t	          d| j         d| j	                   d S d S d S )NzFtype must be either numbers.Integral, numbers.Real or RealNotInt. Got r.   )r   r   bothneitherz@closed must be either 'left', 'right', 'both' or 'neither'. Got z"for an interval over the integers.zExpecting left to be an int zExpecting right to be an int r   r   z"left can't be None when closed ==  r   r   z#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=)
rI   r   r   r   rU   r   r   rB   	TypeErrorr   )rb   suffixs     r   r   zInterval._check_params  s"   9XtZ888-	- - -  
 ;BBB.{. . .  
 9  9Fy$Z	8-L-L$ Gv G GHHHz%jX.N.N% H H HIIIy T[4D%D%D OOOvOO   z!dk5F&F&F P$+PPPP   y$Z	4-H-H$ EFFFz%jT.J.J% FGGG:!di&;
di@W@W&49 & && &   "!&;&;@W@Wr   c                    t          |t                    st          j        |          rdS | j        dv rt
          j        nt
          j        }| j        dv rt
          j        nt
          j	        }| j
        t          j         n| j
        }| j        t          j        n| j        } |||          rdS  |||          rdS dS )NFr   r   T)rB   r   npr   r   operatorltlegtger   infr   )rb   r   left_cmp	right_cmpr   r   s         r   __contains__zInterval.__contains__  s    #x(( 	RXc]] 	5"&+1A"A"A8;;x{#';2C#C#CHKK	)+ww*,$*8C 	59S%   	5tr   c                 8    t          || j                  sdS || v S r   r   r   s     r   r0   zInterval.is_satisfied_by  s%    #ty)) 	5d{r   c                    | j         t          u rdnd}| j        dv rdnd}| j        dn| j        }| j        dn| j        }| j        dv rd	nd
}| j         t          k    s)t          | j        t                    rt          |          }| j         t          k    s)t          | j        t                    rt          |          }| d| | d| | S )Nzan intza floatr   [(z-infr   r   ])z in the range r&   )rI   r   r   r   r   rB   r   r   )rb   type_strleft_bracket
left_boundright_boundright_brackets         r   r   zInterval.__str__  s   #yH4488)"k-===ss3#y0VVdi
#z1eetz#{.???S yH$$DIt)D)D$z**JyH$$DJ)E)E$,,K  H HH'H H+6H8EH H	
r   )
r   r   r   r   r   r   r   r0   r   r   r   s   @r   rK   rK     s        ! !F    % % %N     
 
 
 
 
 
 
r   rK   c                       e Zd ZdZd Zd ZdS )rC   z#Constraint representing array-likesc                      t          |          S r   r   r   s     r   r0   z_ArrayLikes.is_satisfied_by  s    ',,,r   c                     dS )Nzan array-liker   r   s    r   r   z_ArrayLikes.__str__  s    r   Nr   r   r   r   rC   rC     s8        --- - -    r   rC   c                       e Zd ZdZd Zd ZdS )rD   z(Constraint representing sparse matrices.c                      t          |          S r   )r
   r   s     r   r0   z_SparseMatrices.is_satisfied_by      }}r   c                     dS )Nza sparse matrixr   r   s    r   r   z_SparseMatrices.__str__  s      r   Nr   r   r   r   rD   rD     s8        22  ! ! ! ! !r   rD   c                       e Zd ZdZd Zd ZdS )rG   z"Constraint representing callables.c                      t          |          S r   )rF   r   s     r   r0   z_Callables.is_satisfied_by$  r   r   c                     dS )Nz
a callabler   r   s    r   r   z_Callables.__str__'  s    |r   Nr   r   r   r   rG   rG   !  s8        ,,      r   rG   c                   .     e Zd ZdZ fdZd Zd Z xZS )rE   zConstraint representing random states.

    Convenience class for
    [Interval(Integral, 0, 2**32 - 1, closed="both"), np.random.RandomState, None]
    c                     t                                                       t          t          ddd          t	          t
          j        j                  t                      g| _	        d S )Nr   l    r   r   )
r   r   rK   r   rJ   r   randomRandomStaterH   _constraintsrb   r   s    r   r   z_RandomStates.__init__2  sV    Xq)F;;;.//
r   c                 D    t          fd| j        D                       S )Nc              3   B   K   | ]}|                               V  d S r   r0   r    r+   r   s     r   	<genexpr>z0_RandomStates.is_satisfied_by.<locals>.<genexpr>;  1      EEa1$$S))EEEEEEr   anyr   r   s    `r   r0   z_RandomStates.is_satisfied_by:  )    EEEE43DEEEEEEr   c                 z    d                     d | j        d d         D                        d| j        d          S )Nr&   c                 ,    g | ]}t          |          S r   r(   r*   s     r   r"   z)_RandomStates.__str__.<locals>.<listcomp>?      AAAQ#a&&AAAr   r,   r-   r2   r   r   s    r   r   z_RandomStates.__str__=  P    yyAA$*;CRC*@AAABB ( (!"%( (	
r   r   r   s   @r   rE   rE   +  c         
 
 
 
 
F F F
 
 
 
 
 
 
r   rE   c                   .     e Zd ZdZ fdZd Zd Z xZS )rP   z[Constraint representing boolean likes.

    Convenience class for
    [bool, np.bool_]
    c                     t                                                       t          t                    t          t          j                  g| _        d S r   )r   r   rJ   boolr   bool_r   r   s    r   r   z_Booleans.__init__K  sA    ""
r   c                 D    t          fd| j        D                       S )Nc              3   B   K   | ]}|                               V  d S r   r   r   s     r   r   z,_Booleans.is_satisfied_by.<locals>.<genexpr>S  r   r   r  r   s    `r   r0   z_Booleans.is_satisfied_byR  r  r   c                 z    d                     d | j        d d         D                        d| j        d          S )Nr&   c                 ,    g | ]}t          |          S r   r(   r*   s     r   r"   z%_Booleans.__str__.<locals>.<listcomp>W  r  r   r,   r-   r  r   s    r   r   z_Booleans.__str__U  r  r   r   r   s   @r   rP   rP   D  sc         
 
 
 
 
F F F
 
 
 
 
 
 
r   rP   c                   .     e Zd ZdZ fdZd Zd Z xZS )rQ   zHelper constraint for the verbose parameter.

    Convenience class for
    [Interval(Integral, 0, None, closed="left"), bool, numpy.bool_]
    c                     t                                                       t          t          dd d          t	          t
                    t	          t          j                  g| _        d S )Nr   r   r   )	r   r   rK   r   rJ   r  r   r  r   r   s    r   r   z_VerboseHelper.__init__c  sU    Xq$v666""
r   c                 D    t          fd| j        D                       S )Nc              3   B   K   | ]}|                               V  d S r   r   r   s     r   r   z1_VerboseHelper.is_satisfied_by.<locals>.<genexpr>l  r   r   r  r   s    `r   r0   z_VerboseHelper.is_satisfied_byk  r  r   c                 z    d                     d | j        d d         D                        d| j        d          S )Nr&   c                 ,    g | ]}t          |          S r   r(   r*   s     r   r"   z*_VerboseHelper.__str__.<locals>.<listcomp>p  r  r   r,   r-   r  r   s    r   r   z_VerboseHelper.__str__n  r  r   r   r   s   @r   rQ   rQ   \  r	  r   rQ   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )rO   a  Helper 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.

    Fc                 r   t                                                       || _        t          t                    t          t          d d d          t                      t                      g| _	        | j        s<| j	        
                    t          t                    t                      g           d S d S )Nr   r   )r   r   numeric_onlyrJ   r   rK   r   rT   r   r   extendr)   rH   )rb   r  r   s     r   r   zMissingValues.__init__  s    ( ""T4f555!!
   	M$$l3&7&79J9J%KLLLLL	M 	Mr   c                 D    t          fd| j        D                       S )Nc              3   B   K   | ]}|                               V  d S r   r   r   s     r   r   z0MissingValues.is_satisfied_by.<locals>.<genexpr>  r   r   r  r   s    `r   r0   zMissingValues.is_satisfied_by  r  r   c                 z    d                     d | j        d d         D                        d| j        d          S )Nr&   c                 ,    g | ]}t          |          S r   r(   r*   s     r   r"   z)MissingValues.__str__.<locals>.<listcomp>  r  r   r,   r-   r  r   s    r   r   zMissingValues.__str__  r  r   )Fr   r   s   @r   rO   rO   u  sn         &M M M M M MF F F
 
 
 
 
 
 
r   rO   c                   \     e Zd ZdZ edeegid           fd            Zd Zd Z	 xZ
S )rN   aI  Constraint 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)rw   c                     t                                                       t          |t                    r|g}|| _        d S r   )r   r   rB   r)   r!  )rb   r!  r   s     r   r   zHasMethods.__init__  s?    
 	gs## 	 iGr   c                 D    t          fd| j        D                       S )Nc              3   T   K   | ]"}t          t          |d                     V  #d S r   )rF   getattr)r    methodr   s     r   r   z-HasMethods.is_satisfied_by.<locals>.<genexpr>  s7      SSF8GC6677SSSSSSr   )allr!  r   s    `r   r0   zHasMethods.is_satisfied_by  s(    SSSSdlSSSSSSr   c                     t          | j                  dk    r| j        d         }n<d                    d | j        d d         D                        d| j        d         }d| S )Nr   r   r&   c                 ,    g | ]}t          |          S r   )reprr    ms     r   r"   z&HasMethods.__str__.<locals>.<listcomp>  s    AAA!d1ggAAAr   r,   z and zan object implementing )r1   r!  r2   )rb   r!  s     r   r   zHasMethods.__str__  s    t|!!a,GG 99AAt|CRC/@AAABB ) )L$) )  3222r   )r   r   r   r   r}   r)   listr   r0   r   r   r   s   @r   rN   rN     s        	 	 _	S$K &*     	 T T T3 3 3 3 3 3 3r   rN   c                       e Zd ZdZd Zd ZdS )_IterablesNotStringz7Constraint representing iterables that are not strings.c                 X    t          |t                    ot          |t                     S r   )rB   r   r)   r   s     r   r0   z#_IterablesNotString.is_satisfied_by  s$    #x((EC1E1E-EEr   c                     dS )Nzan iterabler   r   s    r   r   z_IterablesNotString.__str__  s    }r   Nr   r   r   r   r/  r/    s;        AAF F F    r   r/  c                   .     e Zd ZdZ fdZd Zd Z xZS )rR   zConstraint representing cv objects.

    Convenient class for
    [
        Interval(Integral, 2, None, closed="left"),
        HasMethods(["split", "get_n_splits"]),
        _IterablesNotString(),
        None,
    ]
    c                     t                                                       t          t          dd d          t	          ddg          t                      t                      g| _        d S )Nr   r   r   splitget_n_splits)r   r   rK   r   rN   r/  rH   r   r   s    r   r   z_CVObjects.__init__  s_    Xq$v666011!!	
r   c                 D    t          fd| j        D                       S )Nc              3   B   K   | ]}|                               V  d S r   r   r   s     r   r   z-_CVObjects.is_satisfied_by.<locals>.<genexpr>  r   r   r  r   s    `r   r0   z_CVObjects.is_satisfied_by  r  r   c                 z    d                     d | j        d d         D                        d| j        d          S )Nr&   c                 ,    g | ]}t          |          S r   r(   r*   s     r   r"   z&_CVObjects.__str__.<locals>.<listcomp>  r  r   r,   r-   r  r   s    r   r   z_CVObjects.__str__  r  r   r   r   s   @r   rR   rR     sc        	 	
 
 
 
 
F F F
 
 
 
 
 
 
r   rR   c                       e Zd ZdZd ZdS )rS   zClass encapsulating a constraint not meant to be exposed to the user.

    Parameters
    ----------
    constraint : str or _Constraint instance
        The constraint to be used internally.
    c                     || _         d S r   rV   )rb   r!   s     r   r   zHidden.__init__  s    $r   N)r   r   r   r   r   r   r   r   rS   rS     s-         % % % % %r   rS   c                 N   t          | t                    rdd                    | j                   S t          | t                    rt          j        g d          S t          | t                    rdS t          | t                    r t          ddi                       S t          | t                    rdS t          | t                    rdS t          | t                    r7| j	        t          u r)| j        
| j        d
z
  S | j        
| j        d
z   S t           t          | t                    rn| j	        t"          t$          fv rY| j        
| j        dz
  S | j        
| j        dz   S | j        dv rt
          j         S | j        dv rt
          j        S t
          j        S t           )a  Return 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.
    znot r-   r   r      r,   HasNotMethodsr   za stringznot a cv objectNr   gư>)r   r   )r   r   )rB   rL   r2   r   rO   r   arrayrQ   rN   rI   r/  rR   rK   r   r   r   NotImplementedErrorr   r   r   r   r@   rV   s    r   generate_invalid_param_valrB    s   " *j)) 87fkk*"455777*m,, #x			"""*n-- r*j)) /,tOR,,...*122 z*j)) !  *h'' "JOx,G,G?&?Q&&'#a'' "!*h'' JOj?Q,Q,Q?&?T))'#d**  444F7N 3336M v
r   c                 T   t          | t                    rt          j        g d          S t          | t                    rt          ddgddgg          S t          | t                    rt          j                            d          S t          | t                    rd S t          | t                    rdS t          | t                    rT| j        t          j        u rt          j        g d          S | j        t          t          fv rdS |                                 S t          | t                     rdS t          | t"                    rdS t          | t$                    r| j        rt          j        S t          | t$                    r	| j        sdS t          | t*                    r( t          d	d
d | j        D                                   S t          | t.                    rg dS t          | t0                    rdS t          | t2                    r| j        D ]}|c S t          | t6                    r^| }|j        	|j        dS |j        
|j        dz
  S |j        
|j        dz   S |j        t          u r|j        |j        z   dz  S |j        dz   S t=          d|            )a1  Return 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=  r   r   *   c                     | S r   r   )xs    r   <lambda>z&generate_valid_param.<locals>.<lambda>S  s     r   NTmissingValidHasMethodsr   c                     i | ]}|d  S )c                     d S r   r   r   s    r   rG  z1generate_valid_param.<locals>.<dictcomp>.<lambda>q  s    D r   r   r+  s     r   rh   z(generate_valid_param.<locals>.<dictcomp>q  s    #U#U#UQA'8'8#U#U#Ur      r   rA   )rB   rC   r   r@  rD   r	   rE   r   r   rG   rH   rJ   rI   ndarrayr   r   rP   rQ   rO   r  r@   rN   r!  r/  rR   rM   r   rK   r   r   rU   )r!   r   intervals      r   generate_valid_paramrO  :  s    *k** #x			"""*o.. ,Aq6Aq6*+++*m,, )y$$R(((*j)) {*o.. t*l++ 	!?bj((8III&&&?x...1   *i(( t*n-- q*m,, 1H v*m,, Z5L y*j)) 
tr#U#U*BT#U#U#U
 
   	 *122 yy*j)) q*g&&  ( 	 	FMMM*h'' )= X^%;1]">A%%^#=1$$}$$ 6!;;}q((
===
>
>>r   )7rz   r   r   rn   abcr   r   collections.abcr   inspectr   numbersr   r   numpyr   scipy.sparser	   r
   _configr   r   
validationr   rU   r   r   r:   r   r}   r   registerr   r   r   rJ   rH   rT   r   rM   rL   rK   rC   rD   rG   rE   rP   rQ   rO   rN   r/  rR   rS   rB  rO  r   r   r   <module>rY     s         				 # # # # # # # # $ $ $ $ $ $       " " " " " " " "     - - - - - - - - 0 0 0 0 0 0 0 0 0 0 0 0 0 0    J	   I I IX)? )? )?XS S Sl          E   
" 
" 
"J J J J J# J J J4; ; ; ; ;; ; ; ;(    k   	 	 	 	 	[ 	 	 	    +   &D &D &D &D &Dk &D &D &DRK K K K K K K K"z
 z
 z
 z
 z
{ z
 z
 z
z    +   ! ! ! ! !k ! ! !       
 
 
 
 
K 
 
 
2
 
 
 
 
 
 
 
0
 
 
 
 
[ 
 
 
2*
 *
 *
 *
 *
K *
 *
 *
Z!3 !3 !3 !3 !3 !3 !3 !3H    +   
 
 
 
 
 
 
 
>
% 
% 
% 
% 
% 
% 
% 
%; ; ;|R? R? R? R? R?r   