B @`u3@sUdZddlmZddlmZmZmZmZddlm Z m Z ddl m Z m Z ddlmZddlmZmZmZGdd d Zd d iZeed d ddZeedd ddZddZddZddZiZeeeeeeffed<ded<ded<d ed<ee edkr d ed<eeddd dZiZ eeeefed <de d<d e d<ee ddd dZ!d!d"Z"d d iZ#eeefed#<ee#d$d d%dZ$d&d'Z%iZ&eeefed(<d e&d)<d e&d <ee&d dd*Z'ee&d+d ddZ(d,d-Z)iZ*eeee+fed.<d e*d)<d e*d <d/e*d0<ee*d1d ddZ,ee*d2d ddZ-d d/d3Z.ee.d4d5Z/d d d/d6Z0ee0d7d ddZ1ee0d8d ddZ2dd9iZ3eeefed:<ee3d;d ddZ4dd iZ5eeefed<<ee5d=d ddZ6d d iZ7eeefed><ee7d?d ddZ8iZ9eeeeeeffed@<de9d<de9d<d e9d<ee9dAd4dBZ:iZ;eeeefedC<d e;d)<d e;d <e;<Z=d e=d<d/e=d0<d e=dD<e;<Z>d e>d<d/e>d0<d e>dD<e;<Z?d/e?dE<d/e?d0<d/e;d0<ee;d4d5Z@ee=dFd ddZAee>dGd ddZBee;dHd ddZCee?dId ddZDiZEeeee+fedJ<d eEd)<d eEd <d/eEd0<eeEd4d5ZFiZGeeeefedK<d eGd <dLeGdM<eeGdNd4dBZHdOdPZIdQd iZJeeJdRd ddZKd dSdTdUZLd dSdVdWZMd dSdXdYZNdcd dSdZd[ZOd\ZPed d]d^d_ZQddeeed d`dadbZRd S)ea 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. ) LooseVersion)AnyDictOptionalUnion) __version__ndarray)is_bool is_integer)UnsupportedFunctionCall) validate_argsvalidate_args_and_kwargsvalidate_kwargsc@s6eZdZdeedddZd eeddddZdS) CompatValidatorN)methodcCs||_||_||_||_dS)N)fnamerdefaultsmax_fname_arg_count)selfrrrrr@/tmp/pip-unpacked-wheel-q9tj5l6a/pandas/compat/numpy/function.py__init__!szCompatValidator.__init__)rreturncCs|s|r|dkr|jn|}|dkr(|jn|}|dkr:|jn|}|dkrXt||||jnD|dkrpt|||jn,|dkrt|||||jntd|ddS)Nargskwargsbothzinvalid validation method '')rrrr rrr ValueError)rrrrrrrrr__call__-szCompatValidator.__call__)NNN)NNN)__name__ __module__ __qualname__rstrrrrrrrr s routNZargminr)rrrZargmaxcCs(t|ts|dkr |f|}d}||fS)NT) isinstancer)skipnarrrrprocess_skipnaSs r'cCst||\}}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&rrrrrvalidate_argmin_with_skipna[s r)cCst||\}}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&rrrrrvalidate_argmax_with_skipnags r+ARGSORT_DEFAULTSaxisZ quicksortkindorderz1.17.0Zargsort)rrrARGSORT_DEFAULTS_KINDcCs0t|s|dkr|f|}d}t||dd|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 ascendingrrrrrvalidate_argsort_with_ascendings  r4 CLIP_DEFAULTSZclipr2cCs&t|tr|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.rrrrrvalidate_clip_with_axiss    r7CUM_FUNC_DEFAULTSdtype)rrZcumsumcCs(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&rrnamerrrvalidate_cum_func_with_skipnas  r<ALLANY_DEFAULTSFkeepdimsallany)r#r>r)r)r.r#r>minmaxCRESHAPE_DEFAULTSZreshapeREPEAT_DEFAULTSrepeatROUND_DEFAULTSround SORT_DEFAULTSsort)rrSTAT_FUNC_DEFAULTSinitialZoverwrite_inputsumprodmeanZmedianSTAT_DDOF_FUNC_DEFAULTS TAKE_DEFAULTSraisemodeZtakecCs4t|ts|dkr |f|}d}t||ddd|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 NTr2r)rr)r%r validate_take)convertrrrrrvalidate_take_with_convert!s  rVZaxesZ transpose)rcCsFd}d|d}t|dkr$t|x|D]}||kr*t|q*WdS)N)r.r9r#z9numpy operations are not valid with window objects. Use .z() directly instead r)lenr )r;rr numpy_argsmsgargrrrvalidate_window_func5s   r[cCsFd}d|d}t|dkr$t|x|D]}||kr*t|q*WdS)N)r.r9r#zFnumpy operations are not valid with window objects. Use .rolling(...).z () instead r)rWr )r;rrrXrYrZrrrvalidate_rolling_funcDs   r\cCsFd}d|d}t|dkr$t|x|D]}||kr*t|q*WdS)N)r.r9r#zHnumpy operations are not valid with window objects. Use .expanding(...).z () instead r)rWr )r;rrrXrYrZrrrvalidate_expanding_funcSs   r]cCsD|dkr g}t|t|}t|t|dkr@td|ddS)z 'args' and 'kwargs' should be empty, except for allowed kwargs because all of their necessary parameters are explicitly listed in the function signature Nrz?numpy operations are not valid with groupby. Use .groupby(...).z () instead)setrWr )r;rrallowedrrrvalidate_groupby_funcbs r`)rArBrMrNrOZstdvar)rrcCs:t|t|dkr6|tkr.td|dntddS)z 'args' and 'kwargs' should be empty because all of their necessary parameters are explicitly listed in the function signature rzAnumpy operations are not valid with resample. Use .resample(...).z () insteadztoo many arguments passed inN)rWRESAMPLER_NUMPY_OPSr TypeError)rrrrrrvalidate_resampler_funcws rd)r.ndimrcCs<|dkr dS||ks(|dkr8||dkr8td|ddS)a 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 ndim : int, default 1 Raises ------ ValueError Nrz4`axis` must be fewer than the number of dimensions ())r)r.rerrrvalidate_minmax_axissrg)N)r$)S__doc__Zdistutils.versionrtypingrrrrZnumpyrrZpandas._libs.libr r Z pandas.errorsr Zpandas.util._validatorsr r rrZARGMINMAX_DEFAULTSr(r*r'r)r+r,r"int__annotations__Zvalidate_argsortr1r3r4r5r6r7r8r:Zvalidate_cumsumr<r=boolZ validate_allZ validate_anyZLOGICAL_FUNC_DEFAULTSZvalidate_logical_funcZMINMAX_DEFAULTSZ validate_minZ validate_maxrDZvalidate_reshaperEZvalidate_repeatrGZvalidate_roundrIZ validate_sortrKcopyZ SUM_DEFAULTSZ PROD_DEFAULTSZMEDIAN_DEFAULTSZvalidate_stat_funcZ validate_sumZ validate_prodZ validate_meanZvalidate_medianrPZvalidate_stat_ddof_funcrQrTrVZTRANSPOSE_DEFAULTSZvalidate_transposer[r\r]r`rbrdrgrrrrs  *