1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
U
®ý°d59ã@sZdZddlmZddlmZmZmZmZddlZ    ddl
m Z ddl m Z mZedeeƒZedeedƒZd    d
„Zd d „Zd dœdd„Zdd„Zd dœdd„Zd dœdd„Zd<dddddœdd„Zd=ddœdd„Zd d!d"œd#d$„Zeddd%œd&d'„ƒZed(d)d%œd*d'„ƒZd+d,d%œd-d'„Zd.d/d0œd1d2„Zd.d/d3œd4d5„Zd6d6d6d7œd8d9„Zd dœd:d;„Z dS)>zV
Module that contains many useful utilities
for validating data or function arguments
é)Ú annotations)ÚIterableÚSequenceÚTypeVarÚoverloadN)Úlib)Úis_boolÚ
is_integerÚBoolishTÚ BoolishNoneTc    Csl|dkrtdƒ‚t|ƒt|ƒkrht|ƒ|}t|ƒ|}|dkrDdnd}t|›d|›d|›d|›d    ƒ‚d
S) zÀ
    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.
    rz*'max_fname_arg_count' must be non-negativeéÚargumentÚ    argumentsz() takes at most ú z (z given)N)Ú
ValueErrorÚlenÚ    TypeError)ÚfnameÚargsÚmax_fname_arg_countÚ compat_argsZ max_arg_countZactual_arg_countr ©rúNd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/util/_validators.pyÚ_check_arg_lengths  ÿrc    Cs |D]–}zR||}||}|dk    r*|dks:|dkr@|dk    r@d}n||k}t|ƒsXtdƒ‚Wn$tk
r~||||k}YnX|std|›d|›dƒ‚qdS)zø
    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
    NFz'match' is not a booleanzthe 'z=' parameter is not supported in the pandas implementation of z())rr)rZ arg_val_dictrÚkeyZv1Zv2ÚmatchrrrÚ_check_for_default_values/s  ÿrÚNone)ÚreturncCs,t||||ƒtt||ƒƒ}t|||ƒdS)a
    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.
 
    Parameters
    ----------
    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 : dict
        A 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, a dict ensures that the original
        order of the keyword arguments is enforced.
 
    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ÚdictÚzipr)rrrrÚkwargsrrrÚ validate_argsUs r"cCs8t|ƒt|ƒ}|r4t|ƒd}t|›d|›dƒ‚dS)z}
    Checks whether 'kwargs' contains any keys that are not
    in 'compat_args' and raises a TypeError if there is one.
    rz'() got an unexpected keyword argument 'ú'N)ÚsetÚlistr)rr!rZdiffZbad_argrrrÚ_check_for_invalid_keys~s r&cCs$| ¡}t|||ƒt|||ƒdS)aÞ
    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)Úcopyr&r)rr!rÚkwdsrrrÚvalidate_kwargs‹s r)cCsht||t| ¡ƒ||ƒtt||ƒƒ}|D] }||kr,t|›d|›dƒ‚q,| |¡t|||ƒdS)aý
    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: dict
        A dictionary of keys that `kwargs` is allowed to
        have and their associated default values.
 
    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.
 
    z-() got multiple values for keyword argument 'r#N)rÚtupleÚvaluesrr rÚupdater))rrr!rrZ    args_dictrrrrÚvalidate_args_and_kwargs¦s(ÿÿ
r-TFÚbool)ÚvalueÚ none_allowedÚ int_allowedrcCsNt|ƒ}|r|p|dk}|r*|p(t|tƒ}|sJtd|›dt|ƒj›dƒ‚|S)aR
    Ensure that argument passed in arg_name can be interpreted as boolean.
 
    Parameters
    ----------
    value : bool
        Value to be validated.
    arg_name : str
        Name of the argument. To be reflected in the error message.
    none_allowed : bool, default True
        Whether to consider None to be a valid boolean.
    int_allowed : bool, default False
        Whether to consider integer value to be a valid boolean.
 
    Returns
    -------
    value
        The same value as input.
 
    Raises
    ------
    ValueError
        If the value is not a valid boolean.
    NzFor argument "z$" expected type bool, received type Ú.)rÚ
isinstanceÚintrÚtypeÚ__name__)r/Zarg_namer0r1Z
good_valuerrrÚvalidate_bool_kwargàs ÿr7)Úvalidate_scalar_dict_valuecCs˜ddlm}|dkr$|dkr$tdƒ‚|dkr>|dk    r>||ƒ}nR|dk    rx|dkrx|rt|ttfƒrtdt|ƒj›dƒ‚n|dk    r|dk    rtdƒ‚||fS)a$
    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
    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'.)    Zpandas.core.missingr9rr3r%r*rr5r6)r/Úmethodr8r9rrrÚvalidate_fillna_kwargs
s 
ÿr<zfloat | Iterable[float]z
np.ndarray)ÚqrcCsjt |¡}d}|jdkrBd|kr,dksfnt| |d¡ƒ‚n$tdd„|Dƒƒsft| |d¡ƒ‚|S)aå
    Validate percentiles (used by describe and quantile).
 
    This function checks if the given float or iterable of floats is a valid percentile
    otherwise raises a ValueError.
 
    Parameters
    ----------
    q: float or iterable of floats
        A single percentile or an iterable of percentiles.
 
    Returns
    -------
    ndarray
        An ndarray of the percentiles if valid.
 
    Raises
    ------
    ValueError if percentiles are not in given interval([0, 1]).
    zApercentiles should all be in the interval [0, 1]. Try {} instead.rr gY@css&|]}d|kodknVqdS)rr Nr)Ú.0ÚqsrrrÚ    <genexpr>Nsz&validate_percentile.<locals>.<genexpr>)ÚnpZasarrayÚndimrÚformatÚall)r=Zq_arrÚmsgrrrÚvalidate_percentile1s
 
rF)Ú    ascendingrcCsdS©Nr©rGrrrÚvalidate_ascendingSsrJzSequence[BoolishT]zlist[BoolishT]cCsdSrHrrIrrrrJXszbool | int | Sequence[BoolishT]zbool | int | list[BoolishT]cs4dddœ‰t|tƒs"t|dfˆŽS‡fdd„|DƒS)z8Validate ``ascending`` kwargs for ``sort_index`` method.FT)r0r1rGcsg|]}t|dfˆŽ‘qSrI)r7)r>Úitem©r!rrÚ
<listcomp>esz&validate_ascending.<locals>.<listcomp>)r3rr7rIrrLrrJ]s
 
z
str | Noneztuple[bool, bool])ÚclosedrcCsFd}d}|dkrd}d}n$|dkr(d}n|dkr6d}ntdƒ‚||fS)a%
    Check that the `closed` argument is among [None, "left", "right"]
 
    Parameters
    ----------
    closed : {None, "left", "right"}
 
    Returns
    -------
    left_closed : bool
    right_closed : bool
 
    Raises
    ------
    ValueError : if argument is not among valid values
    FNTÚleftÚrightz/Closed has to be either 'left', 'right' or None)r)rNZ left_closedZ right_closedrrrÚvalidate_endpointshsrQ)Ú    inclusivercCs6d}t|tƒr"dddddœ |¡}|dkr2tdƒ‚|S)aD
    Check that the `inclusive` argument is among {"both", "neither", "left", "right"}.
 
    Parameters
    ----------
    inclusive : {"both", "neither", "left", "right"}
 
    Returns
    -------
    left_right_inclusive : tuple[bool, bool]
 
    Raises
    ------
    ValueError : if argument is not among valid values
    N)TT)TF)FT)FF)ZbothrOrPZneitherz?Inclusive has to be either 'both', 'neither', 'left' or 'right')r3ÚstrÚgetr)rRZleft_right_inclusiverrrÚvalidate_inclusive‰s
üûÿrUr4)ÚlocÚlengthrcCsZt|ƒstd|›d|›ƒ‚|dkr,||7}d|kr@|ksVntd|›d|›ƒ‚|S)z¼
    Check that we have an integer between -length and length, inclusive.
 
    Standardize negative loc to within [0, length].
 
    The exceptions we raise on failure match np.insert.
    z loc must be an integer between -z and r)r    rÚ
IndexError)rVrWrrrÚvalidate_insert_loc«srYcCs&|tjk    r"|dkr"td|›dƒ‚dS)N)Znumpy_nullableZpyarrowzdtype_backend z= is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.)rZ
no_defaultr)Z dtype_backendrrrÚcheck_dtype_backend½s
 
 
ÿrZ)TF)T)!Ú__doc__Ú
__future__rÚtypingrrrrÚnumpyrAZ pandas._libsrZpandas.core.dtypes.commonrr    r.r4r
r rrr"r&r)r-r7r<rFrJrQrUrYrZrrrrÚ<module>s6   &) ;ÿ*'" !"