/ lib / pandas / util / _validators.pyc
_validators.pyc
  1  o

  2  e��c�E�@sdZddlmZddlmZmZmZmZmZddl	Z	ddl
  3  Zddlm
Z
ddlmZmZedee�Zedeed�Zd	d
  4  �Zdd�Zd>dd�Zdd�Zd>dd�Zd>dd�Z	d?d@dd�ZdAdd�ZdBdCd!d"�ZdDd&d'�ZedEd)d*��ZedFd-d*��ZdGd0d*�ZdHd4d5�Z dId7d8�Z!dJd<d=�Z"dS)KzV
  5  Module that contains many useful utilities
  6  for validating data or function arguments
  7  �)�annotations)�Any�Iterable�Sequence�TypeVar�overloadN)�find_stack_level)�is_bool�
  8  is_integer�BoolishT�BoolishNoneTc	Csl|dkrtd��t|�t|�kr4t|�|}t|�|}|dkr"dnd}t|�d|�d|�d|�d	���d
  9  S)z�
 10      Checks whether 'args' has length of at most 'compat_args'. Raises
 11      a TypeError if that is not the case, similar to in Python when a
 12      function is called with too many arguments.
 13      rz*'max_fname_arg_count' must be non-negative��argument�	argumentsz() takes at most � z (z given)N)�
 14  ValueError�len�	TypeError)�fname�args�max_fname_arg_count�compat_argsZ
max_arg_countZactual_arg_countr�r��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\util\_validators.py�_check_arg_lengths���rc	Cs�|D]J}z)||}||}|dur|dus|dur |dur d}n||k}t|�s,td��Wnty>||||u}Ynw|sLtd|�d|�d���qdS)z�
 15      Check that the keys in `arg_val_dict` are mapped to their
 16      default values as specified in `compat_args`.
 17  
 18      Note that this function is to be called only when it has been
 19      checked that arg_val_dict.keys() is a subset of compat_args
 20      NFz'match' is not a booleanzthe 'z=' parameter is not supported in the pandas implementation of z())r	r)rZarg_val_dictr�key�v1�v2�matchrrr�_check_for_default_values1s* ������r�return�NonecCs,t||||�tt||��}t|||�dS)a
 21      Checks whether the length of the `*args` argument passed into a function
 22      has at most `len(compat_args)` arguments and whether or not all of these
 23      elements in `args` are set to their default values.
 24  
 25      Parameters
 26      ----------
 27      fname : str
 28          The name of the function being passed the `*args` parameter
 29      args : tuple
 30          The `*args` parameter passed into a function
 31      max_fname_arg_count : int
 32          The maximum number of arguments that the function `fname`
 33          can accept, excluding those in `args`. Used for displaying
 34          appropriate error messages. Must be non-negative.
 35      compat_args : dict
 36          A dictionary of keys and their associated default values.
 37          In order to accommodate buggy behaviour in some versions of `numpy`,
 38          where a signature displayed keyword arguments but then passed those
 39          arguments **positionally** internally when calling downstream
 40          implementations, a dict ensures that the original
 41          order of the keyword arguments is enforced.
 42  
 43      Raises
 44      ------
 45      TypeError
 46          If `args` contains more values than there are `compat_args`
 47      ValueError
 48          If `args` contains values that do not correspond to those
 49          of the default values specified in `compat_args`
 50      N)r�dict�zipr)rrrr�kwargsrrr�
validate_argsWs r%cCs8t|�t|�}|rt|�d}t|�d|�d���dS)z}
 51      Checks whether 'kwargs' contains any keys that are not
 52      in 'compat_args' and raises a TypeError if there is one.
 53      rz'() got an unexpected keyword argument '�'N)�set�listr)rr$r�diff�bad_argrrr�_check_for_invalid_keys�s
 54  �r+cCs$|��}t|||�t|||�dS)a�
 55      Checks whether parameters passed to the **kwargs argument in a
 56      function `fname` are valid parameters as specified in `*compat_args`
 57      and whether or not they are set to their default values.
 58  
 59      Parameters
 60      ----------
 61      fname : str
 62          The name of the function being passed the `**kwargs` parameter
 63      kwargs : dict
 64          The `**kwargs` parameter passed into `fname`
 65      compat_args: dict
 66          A dictionary of keys that `kwargs` is allowed to have and their
 67          associated default values
 68  
 69      Raises
 70      ------
 71      TypeError if `kwargs` contains keys not in `compat_args`
 72      ValueError if `kwargs` contains keys in `compat_args` that do not
 73      map to the default values specified in `compat_args`
 74      N)�copyr+r)rr$r�kwdsrrr�validate_kwargs�sr.cCsht||t|���||�tt||��}|D]}||vr&t|�d|�d���q|�|�t|||�dS)a�
 75      Checks whether parameters passed to the *args and **kwargs argument in a
 76      function `fname` are valid parameters as specified in `*compat_args`
 77      and whether or not they are set to their default values.
 78  
 79      Parameters
 80      ----------
 81      fname: str
 82          The name of the function being passed the `**kwargs` parameter
 83      args: tuple
 84          The `*args` parameter passed into a function
 85      kwargs: dict
 86          The `**kwargs` parameter passed into `fname`
 87      max_fname_arg_count: int
 88          The minimum number of arguments that the function `fname`
 89          requires, excluding those in `args`. Used for displaying
 90          appropriate error messages. Must be non-negative.
 91      compat_args: dict
 92          A dictionary of keys that `kwargs` is allowed to
 93          have and their associated default values.
 94  
 95      Raises
 96      ------
 97      TypeError if `args` contains more values than there are
 98      `compat_args` OR `kwargs` contains keys not in `compat_args`
 99      ValueError if `args` contains values not at the default value (`None`)
100      `kwargs` contains keys in `compat_args` that do not map to the default
101      value as specified in `compat_args`
102  
103      See Also
104      --------
105      validate_args : Purely args validation.
106      validate_kwargs : Purely kwargs validation.
107  
108      z-() got multiple values for keyword argument 'r&N)r�tuple�valuesr"r#r�updater.)rrr$rrZ	args_dictrrrr�validate_args_and_kwargs�s(���
109  r2TF�valuecCsNt|�}|r|p|du}|r|pt|t�}|s%td|�dt|�j�d���|S)aR
110      Ensure that argument passed in arg_name can be interpreted as boolean.
111  
112      Parameters
113      ----------
114      value : bool
115          Value to be validated.
116      arg_name : str
117          Name of the argument. To be reflected in the error message.
118      none_allowed : bool, default True
119          Whether to consider None to be a valid boolean.
120      int_allowed : bool, default False
121          Whether to consider integer value to be a valid boolean.
122  
123      Returns
124      -------
125      value
126          The same value as input.
127  
128      Raises
129      ------
130      ValueError
131          If the value is not a valid boolean.
132      NzFor argument "z$" expected type bool, received type �.)r	�
133  isinstance�intr�type�__name__)r3�arg_name�none_allowed�int_allowedZ
134  good_valuerrr�validate_bool_kwarg�s��r<�dict[str, Any]c	sni}d�vrt�fdd�|jD��rd}t|��|�vr9|r*|�d|�d�}t|��|���dd��}�|||<���D]\}}	z|�|�}
135  Wn	tyQYq=w|	||
136  <q=t|�dkr`	|St|�dkrw|���dd��}|d||<|St|�d	kr�d�vr�d
137  }t|��d|�d|�d
�}tj	|t
138  t�d�|d||�d�<|d||�d�<|Sd|�d�}t|��)a�
139      Argument handler for mixed index, columns / axis functions
140  
141      In an attempt to handle both `.method(index, columns)`, and
142      `.method(arg, axis=.)`, we have to do some bad things to argument
143      parsing. This translates all arguments to `{index=., columns=.}` style.
144  
145      Parameters
146      ----------
147      data : DataFrame
148      args : tuple
149          All positional arguments from the user
150      kwargs : dict
151          All keyword arguments from the user
152      arg_name, method_name : str
153          Used for better error messages
154  
155      Returns
156      -------
157      kwargs : dict
158          A dictionary of keyword arguments. Doesn't modify ``kwargs``
159          inplace, so update them with the return value here.
160  
161      Examples
162      --------
163      >>> df = pd.DataFrame(range(2))
164      >>> validate_axis_style_args(df, (str.upper,), {'columns': id},
165      ...                          'mapper', 'rename')
166      {'columns': <built-in function id>, 'index': <method 'upper' of 'str' objects>}
167  
168      This emits a warning
169      >>> validate_axis_style_args(df, (str.upper, id), {},
170      ...                          'mapper', 'rename')
171      {'index': <method 'upper' of 'str' objects>, 'columns': <built-in function id>}
172      �axisc3s�|]}|�vVqdS�Nr)�.0�x�r$rr�	<genexpr>9s�z+validate_axis_style_args.<locals>.<genexpr>z;Cannot specify both 'axis' and any of 'index' or 'columns'.z# got multiple values for argument 'r&rr
�z:Cannot specify both 'axis' and any of 'index' or 'columns'zInterpreting call
173  	'.z(a, b)' as 
174  	'.z�(index=a, columns=b)'.
175  Use named arguments to remove any ambiguity. In the future, using positional arguments for 'index' or 'columns' will raise a 'TypeError'.)�
176  stacklevelzCannot specify all of 'z', 'index', 'columns'.)�any�_AXIS_TO_AXIS_NUMBERr�_get_axis_name�get�itemsrr�warnings�warn�
FutureWarningr)�datarr$r9�method_name�out�msgr>�k�v�axrrBr�validate_axis_style_argssL( �
177  �����rU�validate_scalar_dict_value�boolcCs�ddlm}|dur|durtd��|dur"|dur"||�}||fS|durB|durB|r>t|ttf�r>tdt|�j�d���||fS|durN|durNtd��||fS)a$
178      Validate the keyword arguments to 'fillna'.
179  
180      This checks that exactly one of 'value' and 'method' is specified.
181      If 'method' is specified, this validates that it's a valid method.
182  
183      Parameters
184      ----------
185      value, method : object
186          The 'value' and 'method' keyword arguments for 'fillna'.
187      validate_scalar_dict_value : bool, default True
188          Whether to validate that 'value' is a scalar or dict. Specifically,
189          validate that it is not a list or tuple.
190  
191      Returns
192      -------
193      value, method : object
194      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'.)	�pandas.core.missingrXrr5r(r/rr7r8)r3�methodrVrXrrr�validate_fillna_kwargsns"����r\�q�float | Iterable[float]�
195  np.ndarraycCslt�|�}d}|jdkr"d|krdks nt|�|d���|Stdd�|D��s4t|�|d���|S)a�
196      Validate percentiles (used by describe and quantile).
197  
198      This function checks if the given float or iterable of floats is a valid percentile
199      otherwise raises a ValueError.
200  
201      Parameters
202      ----------
203      q: float or iterable of floats
204          A single percentile or an iterable of percentiles.
205  
206      Returns
207      -------
208      ndarray
209          An ndarray of the percentiles if valid.
210  
211      Raises
212      ------
213      ValueError if percentiles are not in given interval([0, 1]).
214      zApercentiles should all be in the interval [0, 1]. Try {} instead.rr
gY@css(�|]}d|ko
dknVqdS)rr
Nr)r@�qsrrrrC�s�&z&validate_percentile.<locals>.<genexpr>)�np�asarray�ndimr�format�all)r]Zq_arrrQrrr�validate_percentile�s
215  
216  �rf�	ascendingcC�dSr?r�rgrrr�validate_ascending��rj�Sequence[BoolishT]�list[BoolishT]cCrhr?rrirrrrj�rk�bool | int | Sequence[BoolishT]�bool | int | list[BoolishT]cs8ddd��t|t�st|dfi���S�fdd�|D�S)z8Validate ``ascending`` kwargs for ``sort_index`` method.FT)r:r;rgcsg|]}t|dfi����qSri)r<)r@�itemrBrr�
217  <listcomp>�sz&validate_ascending.<locals>.<listcomp>)r5rr<rirrBrrj�s
218  
219  �closed�
220  str | None�tuple[bool, bool]cCsPd}d}|durd}d}||fS|dkrd}||fS|dkr$d}||fStd��)a%
221      Check that the `closed` argument is among [None, "left", "right"]
222  
223      Parameters
224      ----------
225      closed : {None, "left", "right"}
226  
227      Returns
228      -------
229      left_closed : bool
230      right_closed : bool
231  
232      Raises
233      ------
234      ValueError : if argument is not among valid values
235      FNT�left�rightz/Closed has to be either 'left', 'right' or None)r)rr�left_closed�right_closedrrr�validate_endpoints�s���ry�	inclusivecCs6d}t|t�rddddd��|�}|durtd��|S)aD
236      Check that the `inclusive` argument is among {"both", "neither", "left", "right"}.
237  
238      Parameters
239      ----------
240      inclusive : {"both", "neither", "left", "right"}
241  
242      Returns
243      -------
244      left_right_inclusive : tuple[bool, bool]
245  
246      Raises
247      ------
248      ValueError : if argument is not among valid values
249      N)TT�TF)FT)FF)�bothrurv�neitherz?Inclusive has to be either 'both', 'neither', 'left' or 'right')r5�strrIr)rzZleft_right_inclusiverrr�validate_inclusive�s
250  ���r�locr6�lengthcCsZt|�std|�d|����|dkr||7}d|kr |ks+ntd|�d|����|S)z�
251      Check that we have an integer between -length and length, inclusive.
252  
253      Standardize negative loc to within [0, length].
254  
255      The exceptions we raise on failure match np.insert.
256      z loc must be an integer between -z and r)r
257  r�
258  IndexError)r�r�rrr�validate_insert_locsr�)r r!r{)r3rr r)r r=)T)rVrW)r]r^r r_)rgrr r)rgrlr rm)rgrnr ro)rrrsr rt)rzrsr rt)r�r6r�r6r r6)#�__doc__�
259  __future__r�typingrrrrrrK�numpyra�pandas.util._exceptionsr�pandas.core.dtypes.commonr	r
260  rWr6rrrrr%r+r.r2r<rUr\rfrjryrr�rrrr�<module>s8
261  &)
262  
263  ;�
264  *b
265  '"
266  
267  
268  !"