3
pd_4                 @   s  U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZmZ ddlmZmZ ddlmZ ddlmZmZmZ G d	d
 d
ZeddZeeddddZeeddddZdd Zdd Zdd Ze Zddaed< ded< ded< eeedkrded< eeddddZ e Z!d !dbe!d< de!d< ee!ddddZ"d!d" Z#eddZ$ee%ef $ee$d#dd$dZ&d%d& Z'e Z(d'(de(d(< de(d)< ee(ddd*Z)ee(d+dddZ*d,d- Z+e Z,d.,de,d(< de,d)< d/e,d0< ee,d1dddZ-ee,d2dddZ.edd/d3Z/ee/d4d5Z0eddd/d6Z1ee1d7dddZ2ee1d8dddZ3ed9d:Z4ee%e%f 4ee4d;dddZ5edd<Z6ee%ef 6ee6d=dddZ7eddZ8ee%ef 8ee8d>dddZ9e Z:d:dce:d< de:d< de:d< ee:d?d4d@Z;e Z<dA<de<d(< de<d)< e<j= Z>de>d< d/e>d0< de>dB< e<j= Z?de?d< d/e?d0< de?dB< e<j= Z@d/e@dC< d/e@d0< d/e<d0< ee<d4d5ZAee>dDdddZBee?dEdddZCee<dFdddZDee@dGdddZEe ZFd.FdeFd(< deFd)< d/eFd0< eeFd4d5ZGe ZHdHHdeHd)< dIeHdJ< eeHdKd4d@ZIdLdM ZJeddNZKeeKdOdddZLddPdQdRZMddPdSdTZNddPdUdVZOddddPdWdXZPdeZQe%dd[d\d]ZReeS dd^d_d`ZTdS )fa  
For compatibility with numpy libraries, pandas functions or
methods have to accept '*args' and '**kwargs' parameters to
accommodate numpy arguments that are not actually used or
respected in the pandas implementation.

To ensure that users do not abuse these parameters, validation
is performed in 'validators.py' to make sure that any extra
parameters passed correspond ONLY to those in the numpy signature.
Part of that validation includes whether or not the user attempted
to pass in non-default values for these extraneous parameters. As we
want to discourage users from relying on these parameters when calling
the pandas implementation, we want them only to pass in the default values
for these parameters.

This module provides a set of commonly used default arguments for functions
and methods that are spread throughout the codebase. This module will make it
easier to adjust to future upstream changes in the analogous numpy signatures.
    )OrderedDict)LooseVersion)AnyDictOptionalUnion)__version__ndarray)is_bool
is_integer)UnsupportedFunctionCall)validate_argsvalidate_args_and_kwargsvalidate_kwargsc               @   s6   e Zd Zdee dddZd	ee ddddZdS )
CompatValidatorN)methodc             C   s   || _ || _|| _|| _d S )N)fnamer   defaultsmax_fname_arg_count)selfr   r   r   r    r   >/tmp/pip-build-7vycvbft/pandas/pandas/compat/numpy/function.py__init__$   s    zCompatValidator.__init__)r   returnc             C   s   |s|r|d kr| j n|}|d kr(| jn|}|d kr:| jn|}|dkrXt|||| j nD|dkrpt||| j n,|dkrt||||| j ntd| dd S )Nargskwargsbothzinvalid validation method '')r   r   r   r   r   r   r   
ValueError)r   r   r   r   r   r   r   r   r   __call__0   s    zCompatValidator.__call__)NNN)NNN)__name__
__module____qualname__r   strr   r   r   r   r   r   r   #   s       r   N)outZargminr      )r   r   r   Zargmaxc             C   s(   t | ts| d kr | f| }d} | |fS )NT)
isinstancer	   )skipnar   r   r   r   process_skipnaV   s    
r(   c             C   s   t | |\} }t|| | S )a!  
    If 'Series.argmin' is called via the 'numpy' library,
    the third parameter in its signature is 'out', which
    takes either an ndarray or 'None', so check if the
    'skipna' parameter is either an instance of ndarray or
    is None, since 'skipna' itself should be a boolean
    )r(   validate_argmin)r'   r   r   r   r   r   validate_argmin_with_skipna^   s    
r*   c             C   s   t | |\} }t|| | S )a!  
    If 'Series.argmax' is called via the 'numpy' library,
    the third parameter in its signature is 'out', which
    takes either an ndarray or 'None', so check if the
    'skipna' parameter is either an instance of ndarray or
    is None, since 'skipna' itself should be a boolean
    )r(   validate_argmax)r'   r   r   r   r   r   validate_argmax_with_skipnak   s    
r,   z+OrderedDict[str, Optional[Union[int, str]]]axisZ	quicksortkindorderz1.17.0Zargsort)r   r   r   zOrderedDict[str, Optional[int]]c             C   s0   t | s| dkr| f| }d} t||dd | S )a%  
    If 'Categorical.argsort' is called via the 'numpy' library, the
    first parameter in its signature is 'axis', which takes either
    an integer or 'None', so check if the 'ascending' parameter has
    either integer type or is None, since 'ascending' itself should
    be a boolean
    NT   )r   )r   validate_argsort_kind)Z	ascendingr   r   r   r   r   validate_argsort_with_ascending   s
    
r2   Zclipr0   c             C   s&   t | tr| f| }d} t|| | S )a  
    If 'NDFrame.clip' is called via the numpy library, the third
    parameter in its signature is 'out', which can takes an ndarray,
    so check if the 'axis' parameter is an instance of ndarray, since
    'axis' itself should either be an integer or None
    N)r&   r	   validate_clip)r-   r   r   r   r   r   validate_clip_with_axis   s
    


r4   zOrderedDict[str, Any]dtyper$   )r   r   Zcumsumc             C   s(   t | s| f| }d} t|||d | S )z
    If this function is called via the 'numpy' library, the third
    parameter in its signature is 'dtype', which takes either a
    'numpy' dtype or 'None', so check if the 'skipna' parameter is
    a boolean or not
    T)r   )r
   validate_cum_func)r'   r   r   namer   r   r   validate_cum_func_with_skipna   s
    
r8   z OrderedDict[str, Optional[bool]]Fkeepdimsallany)r$   r9   r   )r   )r-   r$   r9   minmaxC)r/   Zreshape)r-   repeatroundsort)r   r   zOrderedDict[str, Optional[Any]]initialZoverwrite_inputsumprodmeanZmedianzOrderedDict[str, Optional[str]]raisemodeZtakec             C   s4   t | ts| dkr | f| }d} t||ddd | S )z
    If this function is called via the 'numpy' library, the third
    parameter in its signature is 'axis', which takes either an
    ndarray or 'None', so check if the 'convert' parameter is either
    an instance of ndarray or is None
    NTr0   r   )r   r   )r&   r	   validate_take)convertr   r   r   r   r   validate_take_with_convert(  s
    
rJ   )ZaxesZ	transpose)r   c             C   sF   d}d|  d}t |dkr$t|x|D ]}||kr*t|q*W d S )Nr-   r5   r$   z9numpy operations are not valid with window objects. Use .z() directly instead r   )r-   r5   r$   )lenr   )r7   r   r   
numpy_argsmsgargr   r   r   validate_window_func=  s    
rO   c             C   sF   d}d|  d}t |dkr$t|x|D ]}||kr*t|q*W d S )Nr-   r5   r$   zFnumpy operations are not valid with window objects. Use .rolling(...).z() instead r   )r-   r5   r$   )rK   r   )r7   r   r   rL   rM   rN   r   r   r   validate_rolling_funcL  s    
rP   c             C   sF   d}d|  d}t |dkr$t|x|D ]}||kr*t|q*W d S )Nr-   r5   r$   zHnumpy operations are not valid with window objects. Use .expanding(...).z() instead r   )r-   r5   r$   )rK   r   )r7   r   r   rL   rM   rN   r   r   r   validate_expanding_func[  s    
rQ   c             C   sD   |dkrg }t |t | }t|t| dkr@td|  ddS )z
    'args' and 'kwargs' should be empty, except for allowed
    kwargs because all of
    their necessary parameters are explicitly listed in
    the function signature
    Nr   z?numpy operations are not valid with groupby. Use .groupby(...).z
() instead)setrK   r   )r7   r   r   allowedr   r   r   validate_groupby_funcj  s    rT   stdvar)r   r   c             C   s:   t |t | dkr6| tkr.td|  dntddS )z
    'args' and 'kwargs' should be empty because all of
    their necessary parameters are explicitly listed in
    the function signature
    r   zAnumpy operations are not valid with resample. Use .resample(...).z
() insteadztoo many arguments passed inN)rK   RESAMPLER_NUMPY_OPSr   	TypeError)r   r   r   r   r   r   validate_resampler_func  s
    rY   )r-   r   c             C   s@   d}| dkrdS | |ks,| dk r<||  dk r<t d| ddS )z
    Ensure that the axis argument passed to min, max, argmin, or argmax is
    zero or None, as otherwise it will be incorrectly ignored.

    Parameters
    ----------
    axis : int or None

    Raises
    ------
    ValueError
    r%   Nr   z4`axis` must be fewer than the number of dimensions ())r   )r-   ndimr   r   r   validate_minmax_axis  s
    r\   r]   r]   )N)r<   r=   rC   rD   rE   rU   rV   )U__doc__collectionsr   distutils.versionr   typingr   r   r   r   numpyr   Z_np_versionr	   Zpandas._libs.libr
   r   Zpandas.errorsr   Zpandas.util._validatorsr   r   r   r   dictZARGMINMAX_DEFAULTSr)   r+   r(   r*   r,   ZARGSORT_DEFAULTSZvalidate_argsortZARGSORT_DEFAULTS_KINDr1   r2   ZCLIP_DEFAULTSr#   r3   r4   ZCUM_FUNC_DEFAULTSr6   Zvalidate_cumsumr8   ZALLANY_DEFAULTSZvalidate_allZvalidate_anyZLOGICAL_FUNC_DEFAULTSZvalidate_logical_funcZMINMAX_DEFAULTSZvalidate_minZvalidate_maxZRESHAPE_DEFAULTSZvalidate_reshapeZREPEAT_DEFAULTSZvalidate_repeatZROUND_DEFAULTSZvalidate_roundZSORT_DEFAULTSZvalidate_sortZSTAT_FUNC_DEFAULTScopyZSUM_DEFAULTSZPROD_DEFAULTSZMEDIAN_DEFAULTSZvalidate_stat_funcZvalidate_sumZvalidate_prodZvalidate_meanZvalidate_medianZSTAT_DDOF_FUNC_DEFAULTSZvalidate_stat_ddof_funcZTAKE_DEFAULTSrH   rJ   ZTRANSPOSE_DEFAULTSZvalidate_transposerO   rP   rQ   rT   rW   rY   intr\   r   r   r   r   <module>   s   *









