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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
Ë
nñúhÅ>ãó—dZddlmZddlmZmZddlZddlm    Z    ddl
m Z m Z m Z mZmZddlmZddlmZmZerdd    lmZdd
lmZdd lmZdd „Zdd „Zdd„Zdd„Zdd„Zdd„Z ddd„Z!dd d„Z"d!d„Z#d„Z$d"d„Z%d#d„Z&d$d„Z'y)%z$
Low-dependency indexing utilities.
é)Ú annotations)Ú TYPE_CHECKINGÚAnyN)Úlib)Ú is_array_likeÚ is_bool_dtypeÚ
is_integerÚis_integer_dtypeÚ is_list_like)ÚExtensionDtype)ÚABCIndexÚ    ABCSeries)Ú AnyArrayLike)Ú    DataFrame)ÚIndexcóėtj|j«xr@tj|j«xrtj|j«S)a(
    Check if a slice object can be interpreted as a positional indexer.
 
    Parameters
    ----------
    slc : slice
 
    Returns
    -------
    bool
 
    Notes
    -----
    A valid positional slice may also be interpreted as a label-based slice
    depending on the index being sliced.
    )rÚis_int_or_noneÚstartÚstopÚstep)Úslcs úMH:\Change_password\venv_build\Lib\site-packages\pandas/core/indexers/utils.pyÚis_valid_positional_slicer&sI€ô$     ×ј3Ÿ9™9Ó%ò    )Ü × Ñ ˜sŸx™xÓ (ò    )ä × Ñ ˜sŸx™xÓ (ðócód—t|«xr$t|t«xrt|«tu S)zœ
    Check if we have a list-like indexer that is *not* a NamedTuple.
 
    Parameters
    ----------
    key : object
 
    Returns
    -------
    bool
    )r Ú
isinstanceÚtupleÚtype)Úkeys rÚis_list_like_indexerr >s-€ô ˜Ó Ò X¤j°´eÓ&<Ò&WÄÀcÃÔRWÐAWÐ!XÐXrcó†—|dk(r t|«ryt|t«r t|«|k(rt    d„|D««Sy)zÓ
    Return True if we are all scalar indexers.
 
    Parameters
    ----------
    indexer : object
    ndim : int
        Number of dimensions in the object being indexed.
 
    Returns
    -------
    bool
    éTc3ó2K—|]}t|«–—Œy­w©N)r    )Ú.0Úxs  rú    <genexpr>z$is_scalar_indexer.<locals>.<genexpr>`sèø€Ò2 Q”:˜a—=Ñ2ùs‚F)r    rrÚlenÚall)ÚindexerÚndims  rÚis_scalar_indexerr,Ns>€ð ˆq‚y”Z Ô(àܐ'œ5Ô!¤c¨'£l°dÒ&:ÜÑ2¨'Ô2Ó2Ð2Ø rcóz—t|«r t|«syt|t«s|f}t    d„|D««S)z‚
    Check if we have an empty indexer.
 
    Parameters
    ----------
    indexer : object
 
    Returns
    -------
    bool
    Tc3ópK—|].}t|tj«xrt|«dk(–—Œ0y­w)rN)rÚnpÚndarrayr()r%Úidxs  rr'z#is_empty_indexer.<locals>.<genexpr>ts+èø€ÒPÀŒz˜#œrŸz™zÓ*Ò<¬s°3«x¸1©}Ó<ÑPùs‚46)r r(rrÚany)r*s rÚis_empty_indexerr3ds7€ôGÔ¤S¨¤\ØÜ gœuÔ %ؐ*ˆÜ ÑPÈÔPÓ PÐPrcó„—d}t|tjtf«rÃt    |«r¶t |«t |«k7r’|j dk(rƒt|t«rtj|«}t|tj«r9|jtjk(r|j«t |«k(s td«‚t |«sd}|St|t«rJt    |«r?t |«t||«k7r|j dk(r td«‚t |«sd}|S)aŠ
    Validate that value and indexer are the same length.
 
    An special-case is allowed for when the indexer is a boolean array
    and the number of true values equals the length of ``value``. In
    this case, no exception is raised.
 
    Parameters
    ----------
    indexer : sequence
        Key for the setitem.
    value : array-like
        Value for the setitem.
    values : array-like
        Values being set into.
 
    Returns
    -------
    bool
        Whether this is an empty listlike setting which is a no-op.
 
    Raises
    ------
    ValueError
        When the indexer is an ndarray or list and the lengths don't match.
    Fr"zKcannot set using a list-like indexer with a different length than the valueTzGcannot set using a slice indexer with a different length than the value)rr/r0Úlistr r(r+ÚarrayÚdtypeÚbool_ÚsumÚ
ValueErrorÚsliceÚlength_of_indexer)r*ÚvalueÚvaluesÚno_ops    rÚcheck_setitem_lengthsr@{s
€ð6 €Eä'œBŸJ™J¬Ð-Ô.ô ˜Ô ܐ7‹|œs 5›zÒ)¨f¯k©k¸QÒ.>ä˜g¤tÔ,Ü Ÿh™h wÓ/Gä˜w¬¯
©
Ô3ØŸ ™ ¬¯©Ò1ØŸ ™ › ¬¨U«Ò3ä$ðAóðôw”<ؐð €Lô
GœUÔ    #Ü ˜Ô ܐ5‹zÔ.¨w¸Ó?Ò?ÀFÇKÁKÐSTÒDTä ð6óðôu”:Øà €Lrcó¨—t|«rG|j«}|dkrd|›d}t|«‚|j«}||k\r t    d«‚yy)a+
    Perform bounds-checking for an indexer.
 
    -1 is allowed for indicating missing values.
 
    Parameters
    ----------
    indices : ndarray
    n : int
        Length of the array being indexed.
 
    Raises
    ------
    ValueError
 
    Examples
    --------
    >>> validate_indices(np.array([1, 2]), 3) # OK
 
    >>> validate_indices(np.array([1, -2]), 3)
    Traceback (most recent call last):
        ...
    ValueError: negative dimensions are not allowed
 
    >>> validate_indices(np.array([1, 2, 3]), 3)
    Traceback (most recent call last):
        ...
    IndexError: indices are out-of-bounds
 
    >>> validate_indices(np.array([-1, -1]), 0) # OK
 
    >>> validate_indices(np.array([0, 1]), 0)
    Traceback (most recent call last):
        ...
    IndexError: indices are out-of-bounds
    éÿÿÿÿz-'indices' contains values less than allowed (z < -1)úindices are out-of-boundsN)r(Úminr:ÚmaxÚ
IndexError)ÚindicesÚnÚmin_idxÚmsgÚmax_idxs     rÚvalidate_indicesrL»s^€ôJ ˆ7„|Ø—+‘+“-ˆØ RŠ<ØAÀ'ÀÈ&ÐQˆCܘS“/Ð !à—+‘+“-ˆØ aŠ<ÜÐ8Ó9Ð 9ð ðrcój—t|t«rHtj|«}t    |«dk(r%tj
dtj ¬«S|dk}|j«r|j«}||xx|z cc<|r&||k\|dkz}|j«r td«‚|S)a&
    Attempt to convert indices into valid, positive indices.
 
    If we have negative indices, translate to positive here.
    If we have indices that are out-of-bounds, raise an IndexError.
 
    Parameters
    ----------
    indices : array-like
        Array of indices that we are to convert.
    n : int
        Number of elements in the array that we are indexing.
    verify : bool, default True
        Check that all entries are between 0 and n - 1, inclusive.
 
    Returns
    -------
    array-like
        An array-like of positive indices that correspond to the ones
        that were passed in initially to this function.
 
    Raises
    ------
    IndexError
        One of the converted indices either exceeded the number of,
        elements (specified by `n`), or was still negative.
    r©r7rC)
rr5r/r6r(ÚemptyÚintpr2ÚcopyrF)rGrHÚverifyÚmasks    rÚmaybe_convert_indicesrTïs™€ô8'œ4Ô Ü—(‘(˜7Ó#ˆÜ ˆw‹<˜1Ò ô—8‘8˜A¤R§W¡WÔ-Ð -à Q‰;€DØ ‡xx„zØ—,‘,“.ˆØ‹ ˜Ñ‹ á Ø˜1‘  ¨1¡Ñ-ˆØ 8‰8Œ:ÜÐ8Ó9Ð 9Ø €Nrcó¨—|‡t|t«rwt|«}|j}|j}|j
}|€d}n
|dkr||z }|||kDr|}n
|dkr||z }|€d}n|dkr |dz|dz}}| }||z
|zdz
|zSt|t ttjtf«rSt|t«rtj|«}|jtk(r|j«St|«St|t«r&|j|jz
|j
zSt!|«syt#d«‚)zX
    Return the expected length of target[indexer]
 
    Returns
    -------
    int
    rr"z%cannot find the length of the indexer)rr;r(rrrrr r/r0r5r6r7Úboolr9Úranger ÚAssertionError)r*ÚtargetÚ
target_lenrrrs      rr<r<"sD€ðМj¨´%Ô8ܘ“[ˆ
Ø— ‘ ˆØ|‰|ˆØ|‰|ˆØ ˆ=؉EØ QŠYØ ZÑ ˆEØ ˆ<˜4 *Ò,؉DØ AŠXØ JÑ ˆDØ ˆ<؉DØ AŠXØ ™( E¨A¡I4ˆEؐ5ˆDؐu‘ ˜tÑ# aÑ'¨DÑ0Ð0Ü    Gœi¬´2·:±:¼tÐDÔ    EÜ gœtÔ $Ü—h‘h˜wÓ'ˆGà =‰=œDÒ  à—;‘;“=Ð  Ü7‹|ÐÜ    GœUÔ    #Ø— ‘ ˜wŸ}™}Ñ,°·±Ñ=Ð=Ü ! 'Ô *ØÜ
Ð@Ó
AÐArcóJ—tj|«dkDr td«‚y)zú
    Helper function to disallow multi-dimensional indexing on 1D Series/Index.
 
    GH#27125 indexer like idx[:, None] expands dim, but we cannot do that
    and keep an index, so we used to return ndarray, which was deprecated
    in GH#30588.
    r"zzMulti-dimensional indexing (e.g. `obj[:, None]`) is no longer supported. Convert to a numpy array before indexing instead.N)r/r+r:)Úresults rÚdisallow_ndim_indexingr]Ls,€ô
‡wwˆvƒ˜ÒÜð Kó
ð    
ðrcóˆ—t|«dk(r3t|dt«r t|t«r t    d«‚|dS|S)z•
    If we have a length-1 tuple/list that contains a slice, unpack to just
    the slice.
 
    Notes
    -----
    The list case is deprecated.
    r"rzYIndexing with a single-item list containing a slice is not allowed. Pass a tuple instead.)r(rr;r5r:)Útups rÚ unpack_1tupler`[sJ€ô ˆ3ƒx1‚}œ C¨¡F¬EÔ2ô cœ4Ô  äð>óð ð
1‰vˆ Ø €Jrcóò—|jr-t|j«t|«k7r td«‚yt|j    |«d«t|j«k7r td«‚y)aÿ
    Checks if a key used as indexer has the same length as the columns it is
    associated with.
 
    Parameters
    ----------
    columns : Index The columns of the DataFrame to index.
    key : A list-like of keys to index with.
    value : DataFrame The value to set for the keys.
 
    Raises
    ------
    ValueError: If the length of key is not equal to the number of columns in value
                or if the number of columns referenced by key is not equal to number
                of columns.
    z"Columns must be same length as keyrN)Ú    is_uniquer(Úcolumnsr:Úget_indexer_non_unique)rcrr=s   rÚcheck_key_lengthressm€ð"×ÒÜ ˆu}‰}Ó ¤ S£Ò )ÜÐAÓBÐ Bð *ô ˆw×-Ñ-¨cÓ2°1Ñ5Ó 6¼#¸e¿m¹mÓ:LÒ LÜÐAÓBÐ Bð Mrcó —t|«dkDr!|dtur|dd}n|dtur|dd}t|«dkDr td«‚|d}|S)z/
    Possibly unpack arr[..., n] to arr[n]
    r"rNrBztoo many indices for array.)r(ÚEllipsisrF)Úitems rÚunpack_tuple_and_ellipsesrisb€ô ˆ4ƒy1‚}à ‰7”hÑ Ø˜˜8‰DØ "‰XœÑ !ؘ˜9ˆDä
ˆ4ƒy1‚}ÜÐ6Ó7Ð7à ‰7€DØ €Krcóº—ddlm}t|«rt|t«r|S|St |«s;||«}t |«dk(r%tjgtj¬«}|j}t|«rt|t«r|jtd¬«}ntj|t¬«}t |«t |«k7r#tdt |«›dt |«›«‚|St!|«r(    tj|tj¬«}|Std
«‚#t"$r}t#d«|‚d    }~wwxYw) aë
    Check if `indexer` is a valid array indexer for `array`.
 
    For a boolean mask, `array` and `indexer` are checked to have the same
    length. The dtype is validated, and if it is an integer or boolean
    ExtensionArray, it is checked if there are missing values present, and
    it is converted to the appropriate numpy array. Other dtypes will raise
    an error.
 
    Non-array indexers (integer, slice, Ellipsis, tuples, ..) are passed
    through as is.
 
    Parameters
    ----------
    array : array-like
        The array that is being indexed (only used for the length).
    indexer : array-like or list-like
        The array-like that's used to index. List-like input that is not yet
        a numpy array or an ExtensionArray is converted to one. Other input
        types are passed through as is.
 
    Returns
    -------
    numpy.ndarray
        The validated indexer as a numpy array that can be used to index.
 
    Raises
    ------
    IndexError
        When the lengths don't match.
    ValueError
        When `indexer` cannot be converted to a numpy ndarray to index
        (e.g. presence of missing values).
 
    See Also
    --------
    api.types.is_bool_dtype : Check if `key` is of boolean dtype.
 
    Examples
    --------
    When checking a boolean mask, a boolean ndarray is returned when the
    arguments are all valid.
 
    >>> mask = pd.array([True, False])
    >>> arr = pd.array([1, 2])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    array([ True, False])
 
    An IndexError is raised when the lengths don't match.
 
    >>> mask = pd.array([True, False, True])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    Traceback (most recent call last):
    ...
    IndexError: Boolean index has wrong length: 3 instead of 2.
 
    NA values in a boolean array are treated as False.
 
    >>> mask = pd.array([True, pd.NA])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    array([ True, False])
 
    A numpy boolean mask will get passed through (if the length is correct):
 
    >>> mask = np.array([True, False])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    array([ True, False])
 
    Similarly for integer indexers, an integer ndarray is returned when it is
    a valid indexer, otherwise an error is  (for integer indexers, a matching
    length is not required):
 
    >>> indexer = pd.array([0, 2], dtype="Int64")
    >>> arr = pd.array([1, 2, 3])
    >>> pd.api.indexers.check_array_indexer(arr, indexer)
    array([0, 2])
 
    >>> indexer = pd.array([0, pd.NA], dtype="Int64")
    >>> pd.api.indexers.check_array_indexer(arr, indexer)
    Traceback (most recent call last):
    ...
    ValueError: Cannot index with an integer indexer containing NA values
 
    For non-integer/boolean dtypes, an appropriate error is raised:
 
    >>> indexer = np.array([0., 2.], dtype="float64")
    >>> pd.api.indexers.check_array_indexer(arr, indexer)
    Traceback (most recent call last):
    ...
    IndexError: arrays used as indices must be of integer or boolean type
    r)r6rNF)r7Úna_valuez Boolean index has wrong length: z  instead of z9Cannot index with an integer indexer containing NA valuesNz9arrays used as indices must be of integer or boolean type)Úpandas.core.constructionr6r rrrr(r/rPr7rr Úto_numpyrVÚasarrayrFr
r:)r6r*Úpd_arrayr7Úerrs     rÚcheck_array_indexerrq£s8€õx;ô GÔÜ gœuÔ %؈Nàˆô ˜Ô !Ù˜7Ó#ˆÜ ˆw‹<˜1Ò ä—h‘h˜r¬¯©Ô1ˆGà M‰M€EܐUÔÜ eœ^Ô ,Ø×&Ñ&¬T¸EÐ&ÓB‰Gä—j‘j ´Ô5ˆGô ˆw‹<œ3˜u›:Ò %ÜØ2ܐw“<.  ¬S°«Z¨Lð:óð ð €Nô
˜%Ô     ð    Ü—j‘j ´·±Ô8ˆGð €NôÐTÓUÐUøô ò    ÜØKóàð ûð    úsÄ%EÅ    EÅ     EÅE)rr;ÚreturnrV)rrrV)r+ÚintrrrV)rGú
np.ndarrayrHrsrrÚNone)T)rHrsrRrVrrrtr$)rrrs)rrru)rcrr=rrrru)rhr)r6rr*rrrr)(Ú__doc__Ú
__future__rÚtypingrrÚnumpyr/Ú pandas._libsrÚpandas.core.dtypes.commonrrr    r
r Úpandas.core.dtypes.dtypesr Úpandas.core.dtypes.genericr rÚpandas._typingrÚpandas.core.framerÚpandas.core.indexes.baserrr r,r3r@rLrTr<r]r`rerirq©rrú<module>r‚sˆðñõ#÷ó
å÷õõ5÷ñ
Ý+å+Ý.ó ó0 Yó ó,Qó.=ó@-:ôh,ôf'BóT 
òó0Có4ô,Fr