
    dr7                    (   d Z ddlmZ ddlmZmZmZmZ ddlZ	ddl
mZ ddlmZmZ  edee          Z edeed          Zd	 Zd
 Zd1dZd Zd1dZd1dZ	 d2d3dZd4d5dZd6dZed7d            Zed8d"            Zd9d%Zd:d)Zd;d+Zd<d/Zd1d0Z dS )=zV
Module that contains many useful utilities
for validating data or function arguments
    )annotations)IterableSequenceTypeVaroverloadN)lib)is_bool
is_integerBoolishTBoolishNoneTc           
        |dk     rt          d          t          |          t          |          k    rIt          |          |z   }t          |          |z   }|dk    rdnd}t          |  d| d| d| d	          d
S )z
    Checks whether 'args' has length of at most 'compat_args'. Raises
    a TypeError if that is not the case, similar to in Python when a
    function is called with too many arguments.
    r   z*'max_fname_arg_count' must be non-negative   argument	argumentsz() takes at most  z (z given)N)
ValueErrorlen	TypeError)fnameargsmax_fname_arg_countcompat_argsmax_arg_countactual_arg_countr   s          S/var/www/html/t/fyr/venv311/lib/python3.11/site-packages/pandas/util/_validators.py_check_arg_lengthr      s     QEFFF
4yy3{####K((+>>t99'::!.!!3!3:: * *} * *x * * * * *
 
 	
 $#    c                   |D ]{}	 ||         }||         }||||d}n||k    }t          |          st          d          n # t          $ r ||         ||         u }Y nw xY w|st          d| d|  d          |dS )z
    Check that the keys in `arg_val_dict` are mapped to their
    default values as specified in `compat_args`.

    Note that this function is to be called only when it has been
    checked that arg_val_dict.keys() is a subset of compat_args
    NFz'match' is not a booleanzthe 'z=' parameter is not supported in the pandas implementation of z())r	   r   )r   arg_val_dictr   keyv1v2matchs          r   _check_for_default_valuesr$   /   s       	:c"BS!B 2:2:".b5>> = !;<<<=
  	: 	: 	: %S)99EEE	:  	: : :05: : :  	/ s   ?AA#"A#returnNonec                    t          | |||           t          t          ||                    }t          | ||           dS )a  
    Checks whether the length of the `*args` argument passed into a function
    has at most `len(compat_args)` arguments and whether or not all of these
    elements in `args` are set to their default values.

    Parameters
    ----------
    fname : str
        The name of the function being passed the `*args` parameter
    args : tuple
        The `*args` parameter passed into a function
    max_fname_arg_count : int
        The maximum number of arguments that the function `fname`
        can accept, excluding those in `args`. Used for displaying
        appropriate error messages. Must be non-negative.
    compat_args : dict
        A dictionary of keys and their associated default values.
        In order to accommodate buggy behaviour in some versions of `numpy`,
        where a signature displayed keyword arguments but then passed those
        arguments **positionally** internally when calling downstream
        implementations, a dict ensures that the original
        order of the keyword arguments is enforced.

    Raises
    ------
    TypeError
        If `args` contains more values than there are `compat_args`
    ValueError
        If `args` contains values that do not correspond to those
        of the default values specified in `compat_args`
    N)r   dictzipr$   )r   r   r   r   kwargss        r   validate_argsr+   U   sK    @ eT#6DDD
 #k4(())FeV[99999r   c                    t          |          t          |          z
  }|r*t          |          d         }t          |  d| d          dS )z}
    Checks whether 'kwargs' contains any keys that are not
    in 'compat_args' and raises a TypeError if there is one.
    r   z'() got an unexpected keyword argument ''N)setlistr   )r   r*   r   diffbad_args        r   _check_for_invalid_keysr2   ~   s_     v;;[)))D Ut**Q-5SSSSSTTTU Ur   c                r    |                                 }t          | ||           t          | ||           dS )a  
    Checks whether parameters passed to the **kwargs argument in a
    function `fname` are valid parameters as specified in `*compat_args`
    and whether or not they are set to their default values.

    Parameters
    ----------
    fname : str
        The name of the function being passed the `**kwargs` parameter
    kwargs : dict
        The `**kwargs` parameter passed into `fname`
    compat_args: dict
        A dictionary of keys that `kwargs` is allowed to have and their
        associated default values

    Raises
    ------
    TypeError if `kwargs` contains keys not in `compat_args`
    ValueError if `kwargs` contains keys in `compat_args` that do not
    map to the default values specified in `compat_args`
    N)copyr2   r$   )r   r*   r   kwdss       r   validate_kwargsr6      s;    , ;;==DE6;777eT;77777r   c                0   t          | |t          |                                          z   ||           t          t	          ||                    }|D ]}||v rt          |  d| d          |                    |           t          | ||           dS )a  
    Checks whether parameters passed to the *args and **kwargs argument in a
    function `fname` are valid parameters as specified in `*compat_args`
    and whether or not they are set to their default values.

    Parameters
    ----------
    fname: str
        The name of the function being passed the `**kwargs` parameter
    args: tuple
        The `*args` parameter passed into a function
    kwargs: dict
        The `**kwargs` parameter passed into `fname`
    max_fname_arg_count: int
        The minimum number of arguments that the function `fname`
        requires, excluding those in `args`. Used for displaying
        appropriate error messages. Must be non-negative.
    compat_args: dict
        A dictionary of keys that `kwargs` is allowed to
        have and their associated default values.

    Raises
    ------
    TypeError if `args` contains more values than there are
    `compat_args` OR `kwargs` contains keys not in `compat_args`
    ValueError if `args` contains values not at the default value (`None`)
    `kwargs` contains keys in `compat_args` that do not map to the default
    value as specified in `compat_args`

    See Also
    --------
    validate_args : Purely args validation.
    validate_kwargs : Purely kwargs validation.

    z-() got multiple values for keyword argument 'r-   N)r   tuplevaluesr(   r)   r   updater6   )r   r   r*   r   r   	args_dictr    s          r   validate_args_and_kwargsr<      s    P teFMMOO,,,.A;   Sd++,,I  &==MMsMMM   
 MM)E6;/////r   TFvaluenone_allowedboolint_allowedc                    t          |           }|r|p| du }|r|pt          | t                    }|s(t          d| dt	          |           j         d          | S )aR  
    Ensure that argument passed in arg_name can be interpreted as boolean.

    Parameters
    ----------
    value : bool
        Value to be validated.
    arg_name : str
        Name of the argument. To be reflected in the error message.
    none_allowed : bool, default True
        Whether to consider None to be a valid boolean.
    int_allowed : bool, default False
        Whether to consider integer value to be a valid boolean.

    Returns
    -------
    value
        The same value as input.

    Raises
    ------
    ValueError
        If the value is not a valid boolean.
    NzFor argument "z$" expected type bool, received type .)r	   
isinstanceintr   type__name__)r=   arg_namer>   r@   
good_values        r   validate_bool_kwargrI      s    6 J 105D=
 :9:eS#9#9
 
,X , ,KK(, , ,
 
 	
 Lr   validate_scalar_dict_valuec                   ddl m} | |t          d          | | ||          }n[| F|D|rAt          | t          t
          f          r%t          dt          |           j         d          n| |t          d          | |fS )a$  
    Validate the keyword arguments to 'fillna'.

    This checks that exactly one of 'value' and 'method' is specified.
    If 'method' is specified, this validates that it's a valid method.

    Parameters
    ----------
    value, method : object
        The 'value' and 'method' keyword arguments for 'fillna'.
    validate_scalar_dict_value : bool, default True
        Whether to validate that 'value' is a scalar or dict. Specifically,
        validate that it is not a list or tuple.

    Returns
    -------
    value, method : object
    r   )clean_fill_methodNz(Must specify a fill 'value' or 'method'.z>"value" parameter must be a scalar or dict, but you passed a ""z)Cannot specify both 'value' and 'method'.)	pandas.core.missingrL   r   rC   r/   r8   r   rE   rF   )r=   methodrJ   rL   s       r   validate_fillna_kwargsrP   
  s    & 655555}CDDD}+""6**		v~% 	*UT5M*J*J 	9!%e!59 9 9  
 
	v1DEEE&=r   qfloat | Iterable[float]
np.ndarrayc                .   t          j        |           }d}|j        dk    r5d|cxk    rdk    s'n t          |                    |dz                      n>t          d |D                       s%t          |                    |dz                      |S )a  
    Validate percentiles (used by describe and quantile).

    This function checks if the given float or iterable of floats is a valid percentile
    otherwise raises a ValueError.

    Parameters
    ----------
    q: float or iterable of floats
        A single percentile or an iterable of percentiles.

    Returns
    -------
    ndarray
        An ndarray of the percentiles if valid.

    Raises
    ------
    ValueError if percentiles are not in given interval([0, 1]).
    zApercentiles should all be in the interval [0, 1]. Try {} instead.r   r   g      Y@c              3  6   K   | ]}d |cxk    odk    nc V  dS )r   r   N ).0qss     r   	<genexpr>z&validate_percentile.<locals>.<genexpr>N  s6      00B1<<<<a<<<<000000r   )npasarrayndimr   formatall)rQ   q_arrmsgs      r   validate_percentilera   1  s    * JqMME NCzQEQSZZ66777  00%00000 	8SZZ66777Lr   	ascendingc                    d S NrV   rb   s    r   validate_ascendingrf   S      Cr   Sequence[BoolishT]list[BoolishT]c                    d S rd   rV   re   s    r   rf   rf   X  rg   r   bool | int | Sequence[BoolishT]bool | int | list[BoolishT]c                p    dddt          | t                    st          | dfi S fd| D             S )z8Validate ``ascending`` kwargs for ``sort_index`` method.FT)r>   r@   rb   c                ,    g | ]}t          |d fi S re   )rI   )rW   itemr*   s     r   
<listcomp>z&validate_ascending.<locals>.<listcomp>e  s,    SSSk<<V<<SSSr   )rC   r   rI   )rb   r*   s    @r   rf   rf   ]  sW     $D99Fi** E"9kDDVDDDSSSSSSSSr   closed
str | Nonetuple[bool, bool]c                b    d}d}| d}d}n!| dk    rd}n| dk    rd}nt          d          ||fS )a%  
    Check that the `closed` argument is among [None, "left", "right"]

    Parameters
    ----------
    closed : {None, "left", "right"}

    Returns
    -------
    left_closed : bool
    right_closed : bool

    Raises
    ------
    ValueError : if argument is not among valid values
    FNTleftrightz/Closed has to be either 'left', 'right' or None)r   )rq   left_closedright_closeds      r   validate_endpointsry   h  s]    " KL~	6			7		JKKK$$r   	inclusivec                    d}t          | t                    rddddd                    |           }|t          d          |S )aD  
    Check that the `inclusive` argument is among {"both", "neither", "left", "right"}.

    Parameters
    ----------
    inclusive : {"both", "neither", "left", "right"}

    Returns
    -------
    left_right_inclusive : tuple[bool, bool]

    Raises
    ------
    ValueError : if argument is not among valid values
    N)TTTF)FT)FF)bothru   rv   neitherz?Inclusive has to be either 'both', 'neither', 'left' or 'right')rC   strgetr   )rz   left_right_inclusives     r   validate_inclusiver     si      6:)S!!  !"%	 
  

 #i.. 	 #M
 
 	
  r   locrD   lengthc                    t          |           st          d| d|           | dk     r| |z  } d| cxk    r|k    sn t          d| d|           | S )z
    Check that we have an integer between -length and length, inclusive.

    Standardize negative loc to within [0, length].

    The exceptions we raise on failure match np.insert.
    z loc must be an integer between -z and r   )r
   r   
IndexError)r   r   s     r   validate_insert_locr     s     c?? RP6PPPPQQQ
QwwvvQFQQQQRRRJr   c                T    | t           j        ur| dvrt          d|  d          d S d S )N)numpy_nullablepyarrowzdtype_backend z= is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.)r   
no_defaultr   )dtype_backends    r   check_dtype_backendr     sQ    CN** ===* * * *   +*==r   )r%   r&   r|   )r=   r   r>   r?   r@   r?   r%   r   )T)rJ   r?   )rQ   rR   r%   rS   )rb   r   r%   r   )rb   rh   r%   ri   )rb   rk   r%   rl   )rq   rr   r%   rs   )rz   rr   r%   rs   )r   rD   r   rD   r%   rD   )!__doc__
__future__r   typingr   r   r   r   numpyrZ   pandas._libsr   pandas.core.dtypes.commonr	   r
   r?   rD   r   r   r   r$   r+   r2   r6   r<   rI   rP   ra   rf   ry   r   r   r   rV   r   r   <module>r      sD    # " " " " "                            
 7:tS))w~tS$77
 
 
(# # #L&: &: &: &:R
U 
U 
U8 8 8 8670 70 70 70v SX' ' ' ' 'T$ $ $ $ $N   D 
   
 
   
T T T T% % % %B       D   $     r   