HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/util/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/util/__pycache__/_validators.cpython-36.pyc
3

���h�4�@s�dZddlmZmZddlZddlZddlmZdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zddd�Zeeeefejd�dd�ZdS)zV
Module that contains many useful utilities
for validating data or function arguments
�)�Iterable�UnionN)�is_boolc	Csl|dkrtd��t|�t|�krht|�|}t|�|}|dkrDdnd}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.
    rz*'max_fname_arg_count' must be non-negative��argumentZ	argumentsz() takes at most � z (z given)N)�
ValueError�len�	TypeError)�fname�args�max_fname_arg_count�compat_argsZ
max_arg_countZactual_arg_countr�r�9/tmp/pip-build-5_djhm0z/pandas/pandas/util/_validators.py�_check_arg_length
srcCs�x�|D]�}yR||}||}|dk	r,|dks<|dkrB|dk	rBd}n||k}t|�sZtd��Wn$tk
r�||||k}YnX|std|�d|�d���qWdS)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 booleanzthe 'z=' parameter is not supported in the pandas implementation of z())rr)rZarg_val_dictr�keyZv1Zv2�matchrrr�_check_for_default_values!s
 rcCs,t||||�tt||��}t|||�dS)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)rrr
r�kwargsrrr�
validate_argsGs rcCs8t|�t|�}|r4t|�d}t|�d|�d���dS)z}
    Checks whether 'kwargs' contains any keys that are not
    in 'compat_args' and raises a TypeError if there is one.
    rz'() got an unexpected keyword argument '�'N)�set�listr
)rrrZdiffZbad_argrrr�_check_for_invalid_keyspsrcCs$|j�}t|||�t|||�dS)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)�copyrr)rrr�kwdsrrr�validate_kwargs}srcCslt||t|j��||�tt||��}x(|D] }||kr.t|�d|�d���q.W|j|�t|||�dS)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 'rN)r�tuple�valuesrrr
�updater)rrrr
rZ	args_dictrrrr�validate_args_and_kwargs�s&

r#cCs0t|�p|dks,td|�dt|�j�d���|S)z; Ensures that argument passed in arg_name is of type bool. NzFor argument "z$" expected type bool, received type �.)rr�type�__name__)�value�arg_namerrr�validate_bool_kwarg�sr)csri}d�kr0t�fdd�|jD��r0d}t|��|�krr|rT|�d|�d�}t|��|j�jdd��}�|||<x@�j�D]4\}}	y|j|�}
Wntk
r�Yq|X|	||
<q|Wt|�dkr�n�t|�dkr�|j�jdd��}|d||<n�t|�d	k�rZd�k�rd
}t|��d|�d|�d
�}tj	|t
dd�|d||jd�<|d||jd�<nd|�d�}t|��|S)aw
    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._validate_axis_style_args((str.upper,), {'columns': id},
    ...                              'mapper', 'rename')
    {'columns': <function id>, 'index': <method 'upper' of 'str' objects>}

    This emits a warning
    >>> df._validate_axis_style_args((str.upper, id), {},
    ...                              'mapper', 'rename')
    {'columns': <function id>, 'index': <method 'upper' of 'str' objects>}
    �axisc3s|]}|�kVqdS)Nr)�.0�x)rrr�	<genexpr>sz+validate_axis_style_args.<locals>.<genexpr>z;Cannot specify both 'axis' and any of 'index' or 'columns'.z# got multiple values for argument 'rrr�z:Cannot specify both 'axis' and any of 'index' or 'columns'zInterpreting 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'.�)�
stacklevelzCannot specify all of 'z', 'index', 'columns'.)�anyZ_AXIS_TO_AXIS_NUMBERr
Z_get_axis_name�get�itemsrr	�warnings�warn�
FutureWarning)�datarrr(�method_name�out�msgr*�k�vZaxr)rr�validate_axis_style_args�s@% 
r=TcCs�ddlm}|dkr&|dkr&td��nl|dkr@|dk	r@||�}nR|dk	rz|dkrz|r�t|ttf�r�tdt|�j�d���n|dk	r�|dk	r�td��||fS)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'.)	Zpandas.core.missingr>r�
isinstancerr r
r%r&)r'�methodZvalidate_scalar_dict_valuer>rrr�validate_fillna_kwargs9s

rB)�q�returncCsltj|�}d}|jdkrDd|ko*dknsht|j|d���n$tdd�|D��sht|j|d���|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.rrgY@css&|]}d|kodknVqdS)rrNr)r+�qsrrrr-}sz&validate_percentile.<locals>.<genexpr>)�npZasarray�ndimr�format�all)rCZq_arrr:rrr�validate_percentile`s

rJ)T)�__doc__Ztypingrrr4ZnumpyrFZpandas.core.dtypes.commonrrrrrrr#r)r=rB�floatZndarrayrJrrrr�<module>s&)
8
_
'