ó
šxŠ\c           @   sz   d  Z  d d l Z d d l m Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z e d „ Z d S(   sV   
Module that contains many useful utilities
for validating data or function arguments
iÿÿÿÿN(   t   is_boolc      
   C   sœ   | d k  r t  d ƒ ‚ n  t | ƒ t | ƒ k r˜ t | ƒ | } t | ƒ | } | d k re d n d } t d j d |  d | d | d	 | ƒ ƒ ‚ n  d
 S(   sÁ   
    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.

    i    s*   'max_fname_arg_count' must be non-negativei   t   argumentt	   argumentss@   {fname}() takes at most {max_arg} {argument} ({given_arg} given)t   fnamet   max_argt	   given_argN(   t
   ValueErrort   lent	   TypeErrort   format(   R   t   argst   max_fname_arg_countt   compat_argst   max_arg_countt   actual_arg_countR   (    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   _check_arg_length
   s    	c         C   sÜ   xÕ | D]Í } yx | | } | | } | d k	 r< | d k sT | d k r] | d k	 r] t } n | | k } t | ƒ s„ t d ƒ ‚ n  Wn% t k
 r¬ | | | | k } n X| s t d j d |  d | ƒ ƒ ‚ q q Wd S(   sù   
    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

    s   'match' is not a booleansP   the '{arg}' parameter is not supported in the pandas implementation of {fname}()R   t   argN(   t   Nonet   FalseR    R   R	   (   R   t   arg_val_dictR   t   keyt   v1t   v2t   match(    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   _check_for_default_values    s    	

	c         C   s<   t  |  | | | ƒ t t | | ƒ ƒ } t |  | | ƒ d S(   sG  
    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.

    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: OrderedDict
        A ordered 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, an ordered dictionary ensures that the original
        order of the keyword arguments is enforced. Note that if there is
        only one key, a generic dict can be passed in as well.

    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   t   dictt   zipR   (   R   R
   R   R   t   kwargs(    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   validate_argsH   s    !c         C   sQ   t  | ƒ t  | ƒ } | rM t | ƒ d } t d j d |  d | ƒ ƒ ‚ n  d S(   s~   
    Checks whether 'kwargs' contains any keys that are not
    in 'compat_args' and raises a TypeError if there is one.

    i    s4   {fname}() got an unexpected keyword argument '{arg}'R   R   N(   t   sett   listR   R	   (   R   R   R   t   difft   bad_arg(    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   _check_for_invalid_keysr   s
    c         C   s0   | j  ƒ  } t |  | | ƒ t |  | | ƒ d S(   sß  
    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(   t   copyR!   R   (   R   R   R   t   kwds(    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   validate_kwargs‚   s    c         C   s—   t  |  | t | j ƒ  ƒ | | ƒ t t | | ƒ ƒ } x; | D]3 } | | k r? t d j d |  d | ƒ ƒ ‚ q? q? W| j | ƒ t |  | | ƒ d S(   se  
    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: OrderedDict
        A ordered dictionary of keys that `kwargs` is allowed to
        have and their associated default values. Note that if there
        is only one key, a generic dict can be passed in as well.

    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.

    s:   {fname}() got multiple values for keyword argument '{arg}'R   R   N(	   R   t   tuplet   valuesR   R   R   R	   t   updateR$   (   R   R
   R   R   R   t	   args_dictR   (    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   validate_args_and_kwargs    s    -
c         C   sF   t  |  ƒ p |  d k sB t d j d | d t |  ƒ j ƒ ƒ ‚ n  |  S(   s;    Ensures that argument passed in arg_name is of type bool. s=   For argument "{arg}" expected type bool, received type {typ}.R   t   typN(   R    R   R   R	   t   typet   __name__(   t   valuet   arg_name(    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   validate_bool_kwargÝ   s
    c            sí  i  } d ˆ  k rF t  ‡  f d †  |  j Dƒ ƒ rF d } t | ƒ ‚ n  | ˆ  k r¥ | ry d j | | ƒ } t | ƒ ‚ n  |  j ˆ  j d d ƒ ƒ } ˆ  | | | <n  xK ˆ  j ƒ  D]= \ } }	 y |  j | ƒ }
 Wn t k
 rä q² X|	 | |
 <q² Wt | ƒ d k rná t | ƒ d k rF|  j ˆ  j d d ƒ ƒ } | d | | <n£ t | ƒ d k rÎd ˆ  k ryd } t | ƒ ‚ n  d	 } t	 j
 | j d
 | ƒ t d d ƒ| d | |  j d <| d | |  j d <n d } t | j | ƒ ƒ ‚ | S(   sz  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 or Panel
    arg : 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>}
    t   axisc         3   s   |  ] } | ˆ  k Vq d  S(   N(    (   t   .0t   x(   R   (    s6   lib/python2.7/site-packages/pandas/util/_validators.pys	   <genexpr>  s    s;   Cannot specify both 'axis' and any of 'index' or 'columns'.s(   {} got multiple values for argument '{}'i    i   i   s:   Cannot specify both 'axis' and any of 'index' or 'columns'sß   Interpreting call
	'.{method_name}(a, b)' as 
	'.{method_name}(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'.t   method_namet
   stackleveli   s/   Cannot specify all of '{}', 'index', 'columns'.(   t   anyt   _AXIS_NUMBERSR   R	   t   _get_axis_namet   gett   itemsR   R   t   warningst   warnt   FutureWarningt   _AXIS_NAMES(   t   dataR
   R   R.   R3   t   outt   msgR0   t   kt   vt   ax(    (   R   s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   validate_axis_style_argsæ   sD    $+c         C   sæ   d d l  m } |  d k r7 | d k r7 t d ƒ ‚ n¥ |  d k r^ | d k	 r^ | | ƒ } n~ |  d k	 rµ | d k rµ | rÜ t |  t t f ƒ rÜ t d j t	 |  ƒ j
 ƒ ƒ ‚ qÜ n' |  d k	 rÜ | d k	 rÜ t d ƒ ‚ n  |  | f S(   s  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
    iÿÿÿÿ(   t   clean_fill_methods(   Must specify a fill 'value' or 'method'.sB   "value" parameter must be a scalar or dict, but you passed a "{0}"s)   Cannot specify both 'value' and 'method'.N(   t   pandas.core.missingRE   R   R   t
   isinstanceR   R%   R   R	   R+   R,   (   R-   t   methodt   validate_scalar_dict_valueRE   (    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   validate_fillna_kwargsE  s    	(   t   __doc__R:   t   pandas.core.dtypes.commonR    R   R   R   R!   R$   R)   R/   RD   t   TrueRJ   (    (    (    s6   lib/python2.7/site-packages/pandas/util/_validators.pyt   <module>   s   		(	*			=			_