
    aVgC                    0   d Z ddlmZ ddlmZmZmZmZmZ ddl	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ddZd ZddZ	 	 ddZ	 d	 	 	 ddZ	 	 ddZdddZddZed d       Zed!d       Z	 	 	 	 d"dZd#dZ d$dZ!d%dZ"y)&zV
Module that contains many useful utilities
for validating data or function arguments
    )annotations)AnyIterableSequenceTypeVaroverloadN)find_stack_level)is_bool
is_integerBoolishTBoolishNoneTc           
         |dk  rt        d      t        |      t        |      kD  r<t        |      |z   }t        |      |z   }|dk(  rdnd}t        |  d| d| d| d	      y
)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          X/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/util/_validators.py_check_arg_lengthr      s     QEFF
4y3{##K(+>>t9'::!.!!3:g&}oQxj A !*
 	
 $    c                    |D ]H  }	 ||   }||   }||||d}n||k(  }t        |      st        d      	 |r8t        d| d|  d       y# t        $ r ||   ||   u }Y ,w xY w)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%   1   s      	:c"BS!B 2:2:".b5> !;<< " u 005wb: 1(  	: %S)99E	:s   0AA%$A%c                d    t        | |||       t        t        ||            }t        | ||       y)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*   W   s3    @ eT#6D
 #k4()FeV[9r   c                t    t        |      t        |      z
  }|rt        |      d   }t        |  d| d      y)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_keysr1      sF     v;[))Dt*Q-5'!H	QRSTT r   c                X    |j                         }t        | ||       t        | ||       y)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)copyr1   r%   )r   r)   r   kwdss       r   validate_kwargsr5      s'    , ;;=DE6;7eT;7r   c                    t        | |t        |j                               z   ||       t        t	        ||            }|D ]  }||v st        |  d| d       |j                  |       t        | ||       y)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   updater5   )r   r   r)   r   r   	args_dictr!   s          r   validate_args_and_kwargsr;      s    P teFMMO,,.A; Sd+,I &='Fse1M  MM)E6;/r   c                    t        |       }|r|xs | du }|r|xs 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__)valuearg_namenone_allowedint_allowed
good_values        r   validate_bool_kwargrG      sl    6 J05D=
9:eS#9
XJ 'K((),
 	
 Lr   c                   i }dv r+t        fd| j                  D              rd}t        |      |v r>|r| d| d}t        |      | j                  j	                  dd            }|   ||<   j                         D ]  \  }}		 | j                  |      }
|	||
<    t        |      dk(  r	 |S t        |      dk(  r+| j                  j	                  dd            }|d   ||<   |S t        |      dk(  rndv rd	}t        |      d
| d| d}t        j                  |t        t                      |d   || j                  d      <   |d   || j                  d      <   |S d| d}t        |      # t        $ r Y w xY w)a  
    Argument handler for mixed index, columns / axis functions

    In an attempt to handle both `.method(index, columns)`, and
    `.method(arg, axis=.)`, we have to do some bad things to argument
    parsing. This translates all arguments to `{index=., columns=.}` style.

    Parameters
    ----------
    data : DataFrame
    args : tuple
        All positional arguments from the user
    kwargs : dict
        All keyword arguments from the user
    arg_name, method_name : str
        Used for better error messages

    Returns
    -------
    kwargs : dict
        A dictionary of keyword arguments. Doesn't modify ``kwargs``
        inplace, so update them with the return value here.

    Examples
    --------
    >>> df = pd.DataFrame(range(2))
    >>> validate_axis_style_args(df, (str.upper,), {'columns': id},
    ...                          'mapper', 'rename')
    {'columns': <built-in function id>, 'index': <method 'upper' of 'str' objects>}

    This emits a warning
    >>> validate_axis_style_args(df, (str.upper, id), {},
    ...                          'mapper', 'rename')
    {'index': <method 'upper' of 'str' objects>, 'columns': <built-in function id>}
    axisc              3  &   K   | ]  }|v  
 y wN ).0xr)   s     r   	<genexpr>z+validate_axis_style_args.<locals>.<genexpr>9  s     OVOs   z;Cannot specify both 'axis' and any of 'index' or 'columns'.z# got multiple values for argument 'r,   r   r      z:Cannot specify both 'axis' and any of 'index' or 'columns'zInterpreting call
	'.z(a, b)' as 
	'.z(index=a, columns=b)'.
Use named arguments to remove any ambiguity. In the future, using positional arguments for 'index' or 'columns' will raise a 'TypeError'.)
stacklevelzCannot specify all of 'z', 'index', 'columns'.)any_AXIS_TO_AXIS_NUMBERr   _get_axis_namegetitemsr   r   warningswarnFutureWarningr	   )datar   r)   rC   method_nameoutmsgrI   kvaxs     `        r   validate_axis_style_argsra     s   P C
 COT5N5NOOKn 6 M!DXJaPCC. ""6::fa#898$D	  1	$$Q'B CG 4yA~. J- 
Ta""6::fa#89GD	( J' 
TaVNCC.  &k] 3 M " 	 	c=5E5GH&*1gD"#&*1gD"# J (z1GHnA  		s   E;;	FFc                    ddl m} | |t        d      | | ||      }| |fS | @|>|r8t        | t        t
        f      r"t        dt        |       j                   d      | |fS | |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_methodz(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.missingrc   r   r>   r.   r7   r   r@   rA   )rB   methodvalidate_scalar_dict_valuerc   s       r   validate_fillna_kwargsrh   n  s    & 6}CDD	6-"6* &= 
	v~%*UT5M*J!!%e!5!5 6a9  &= 
	v1DEE&=r   c                   t        j                  |       }d}|j                  dk(  r,d|cxk  rdk  sn t        |j	                  |dz              |S t        d |D              st        |j	                  |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  <   K   | ]  }d |cxk  xr dk  nc   yw)r   r   NrL   )rM   qss     r   rO   z&validate_percentile.<locals>.<genexpr>  s     0B1<a<<0s   )npasarrayndimr   formatall)qq_arrr]   s      r   validate_percentilers     s{    * JJqME NCzzQEQSZZ677 L 0%00SZZ677Lr   c                     y rK   rL   	ascendings    r   validate_ascendingrw         r   c                     y rK   rL   ru   s    r   rw   rw     rx   r   c                    ddd}t        | t              st        | dfi |S | D cg c]  }t        |dfi | c}S c c}w )z8Validate ``ascending`` kwargs for ``sort_index`` method.FT)rD   rE   rv   )r>   r   rG   )rv   r)   items      r   rw   rw     sK     $D9Fi*"9kDVDDIRSk<V<SSSs   >c                `    d}d}| d}d}||fS | dk(  rd}||fS | dk(  rd}||fS t        d      )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
    FTleftrightz/Closed has to be either 'left', 'right' or None)r   )closedleft_closedright_closeds      r   validate_endpointsr     sp    " KL~ $$ 
6	 $$ 
7	 $$ JKKr   c                p    d}t        | t              rdddddj                  |       }|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)bothr}   r~   neitherz?Inclusive has to be either 'both', 'neither', 'left' or 'right')r>   strrU   r   )	inclusiveleft_right_inclusives     r   validate_inclusiver     sU      6:)S! !"%	 

 #i. 	 #M
 	
  r   c                    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)loclengths     r   validate_insert_locr     s_     c?:6(%xPQQ
Qwvv;F85QRRJr   )returnNoner   )rB   r   r   r   )r   zdict[str, Any])T)rg   bool)rq   zfloat | Iterable[float]r   z
np.ndarray)rv   r   r   r   )rv   zSequence[BoolishT]r   zlist[BoolishT])rv   zbool | int | Sequence[BoolishT]r   zbool | int | list[BoolishT])r   
str | Noner   tuple[bool, bool])r   r   r   r   )r   r?   r   r?   r   r?   )#__doc__
__future__r   typingr   r   r   r   r   rW   numpyrl   pandas.util._exceptionsr	   pandas.core.dtypes.commonr
   r   r   r?   r   r   r   r%   r*   r1   r5   r;   rG   ra   rh   rs   rw   r   r   r   rL   r   r   <module>r      s    #    4
 :tS)~tS$7
(#L&:R
U8670	70v CH'''T__D$ND 
 
 
 
T.T T%B Dr   