_validators.pyc
1 o 2 e��c�E � @ s d Z ddlmZ ddlmZmZmZmZmZ ddl Z ddl 3 Zddlm Z ddlmZmZ edee�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 C sl |dk rt d��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 r z*'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_length s ���r c C s� |D ]J}z)|| }|| }|dur|du s|du r |dur d}n||k}t |�s,td��W n ty> || || u }Y nw |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 )r Zarg_val_dictr �key�v1�v2�matchr r r �_check_for_default_values1 s* ������r �return�Nonec C s, 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 )r r r r �kwargsr r r � validate_argsW s r% c C s8 t |�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 r z'() got an unexpected keyword argument '�'N)�set�listr )r r$ r �diff�bad_argr r r �_check_for_invalid_keys� s 54 �r+ c C s$ |� � }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 )r r$ r �kwdsr r r �validate_kwargs� s r. c C sh t | |t|�� � ||� tt||��}|D ]}||v r&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&