zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
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
U
¬ý°døSã@sddlmZddlZddlmZmZmZddlZddl    m
Z m Z ddl mZmZmZddlmZddlmZmZddlmZdd    lmZer¤dd
lmZdd lmZed>d ddd dœdd„ƒZed?dddddœdd„ƒZde jdfdddddœdd„Zd dddd dœdd„Z d@ddddddœdd „Z!ej"fd d!d d"œd#d$„Z#ej$d%d&d'd(d(dd)œd*d+„ƒZ%dAd'd(d(dd)œd,d-„Z&dBd.d/„Z'd0d1„Z(e j)e j*e j+e j,e j-e j.e j/e j0e j1e j2e j3e j4e j5e j6e j7e j8e j9e'e j:ej;ej;ƒe'e j<ej;dƒe'e j4ej=ej=ej=ƒe'e j4ej=ej=ej=ƒd2œZ>e j?e j@e jAe jBe jCe jDe jEe jFe jGe jHe jIe jJe jKe jLe jMe jNe jOe'e jPej;ej;ƒe'e jQej;dƒe'e jJej=ej=ej=d3e'e jJej=ej=ej=d3d2œZRe jSe jTe jUe jVe jWe jXe jYe jZe j[e j\e j]e j^e j_e j`e jae jbe jce'e jdej;ej;ƒe'e jeej;dƒe'e j^ej=ej=ej=d3e'e j^ej=ej=ej=d3d2œZfe jge jhe jie jje jke jle jme jne joe jpe jqe jre jse jte jue jve jwe'e jxej;ej;ƒe'e jyej;dƒe'e jrej=ej=ej=d3e'e jrej=ej=ej=d3d2œZzd dd dd4d5œd6d7„Z{d d!d d4d8œd9d:„Z|dCd dddd;œd<d=„Z}dS)Dé)Ú annotationsN)Ú TYPE_CHECKINGÚcastÚoverload)ÚalgosÚlib)Ú    ArrayLikeÚAxisIntÚnpt)Ú maybe_promote)Úensure_platform_intÚis_1d_only_ea_obj)Úna_value_for_dtype)Úensure_wrapped_if_datetimelike)ÚNDArrayBackedExtensionArray)ÚExtensionArray.ú
np.ndarrayr    Úbool)ÚarrÚaxisÚ
allow_fillÚreturncCsdS©N©©rÚindexerrÚ
fill_valuerrrúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/array_algos/take.pyÚtake_nd$srrrcCsdSrrrrrrr/sTcCs²|tjkrt|jdd}n>t|jtjƒrX|jjdkrXt|j|ƒ\}}|j|krX| |¡}t|tj    ƒs˜t
|ƒsˆt d|ƒ}|j ||||dS|j |||dSt  |¡}t|||||ƒS)a1
    Specialized Cython take which sets NaN values in one pass
 
    This dispatches to ``take`` defined on ExtensionArrays. It does not
    currently dispatch to ``SparseArray.take`` for sparse ``arr``.
 
    Note: this function assumes that the indexer is a valid(ated) indexer with
    no out of bound indices.
 
    Parameters
    ----------
    arr : np.ndarray or ExtensionArray
        Input array.
    indexer : ndarray
        1-D array of indices to take, subarrays corresponding to -1 value
        indices are filed with fill_value
    axis : int, default 0
        Axis to take from
    fill_value : any, default np.nan
        Fill value to replace -1 values with
    allow_fill : bool, default True
        If False, indexer is assumed to contain no -1 values so no filling
        will be done.  This short-circuits computation of a mask.  Result is
        undefined if allow_fill == False and -1 is present in indexer.
 
    Returns
    -------
    subarray : np.ndarray or ExtensionArray
        May be the same type as the input, or cast to an ndarray.
    F)ÚcompatZmMr)rrr©rr)rÚ
no_defaultrÚdtypeÚ
isinstanceÚnpÚkindr ÚastypeÚndarrayr rÚtakeZasarrayÚ_take_nd_ndarray)rrrrrr"rrrr:s$%
 
 
 
ÿ
znpt.NDArray[np.intp] | None)rrrrrc Cs
|dkr2tj|j|tjd}|j|j ¡}}nt|ƒ}t||||ƒ\}}}d}|jdkrh|j    j
rhd}|r€|j }|j|d}t |jƒ}t |ƒ||<t|ƒ}    |j    j
rÆ||jdkrÆtj|    |dd}
ntj|    |d}
t|j|j|
j||d} | |||
|ƒ|r|
j }
|
S)    N©r"FéTéÚF)r"Úorder©rÚ    mask_info)r$ZarangeÚshapeZintpr"Útyper Ú'_take_preprocess_indexer_and_fill_valueÚndimÚflagsÚ f_contiguousÚTÚlistÚlenÚtupleÚemptyÚ_get_take_nd_function) rrrrrr"r0Z
flip_orderZ
out_shape_Ú    out_shapeÚoutÚfuncrrrr)xsBÿ
 
 ÿr)znpt.NDArray[np.intp]znpt.NDArray[np.bool_] | None)rrrÚmaskrc    Cszt|tjƒs|j|||dS|s*| |¡St|||d|ƒ\}}}tj|j|d}t|j|j    |j    d|d}|||||ƒ|S)ao
    Specialized version for 1D arrays. Differences compared to `take_nd`:
 
    - Assumes input array has already been converted to numpy array / EA
    - Assumes indexer is already guaranteed to be intp dtype ndarray
    - Only works for 1D arrays
 
    To ensure the lowest possible overhead.
 
    Note: similarly to `take_nd`, this function assumes that the indexer is
    a valid(ated) indexer with no out of bound indices.
 
    Parameters
    ----------
    arr : np.ndarray or ExtensionArray
        Input array.
    indexer : ndarray
        1-D array of indices to take (validated indices, intp dtype).
    fill_value : any, default np.nan
        Fill value to replace -1 values with
    allow_fill : bool, default True
        If False, indexer is assumed to contain no -1 values so no filling
        will be done.  This short-circuits computation of a mask. Result is
        undefined if allow_fill == False and -1 is present in indexer.
    mask : np.ndarray, optional, default None
        If `allow_fill` is True, and the mask (where indexer == -1) is already
        known, it can be passed to avoid recomputation.
    r Tr*rr/)
r#r$r'r(r3r;r1r<r4r")    rrrrr@r"r0r>r?rrrÚtake_1d©s*# 
ÿ
ÿrAz1tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]])rrrcCsb|dk    s t‚|ddk    st‚|ddk    s,t‚|\}}t|ƒ}t|ƒ}||f}d}t|j|ƒ\}}||jkr´|dk}|dk}| ¡}    | ¡}
||f|    |
ff}|    s´|
s´|j|j ¡}}t|ƒt|ƒf} tj| |d} t     
|jj | jj fd¡} | dkr0|j| jkr0t     
| jj | jj fd¡} | dk    r0t | | jƒ} | dk    rL| ||| |dnt ||| ||d| S)zD
    Specialized Cython take which sets NaN values in one pass.
    Nrr,éÿÿÿÿr*)r>r)rr0)ÚAssertionErrorr r r"Úanyr2r9r$r;Ú_take_2d_multi_dictÚgetÚnameÚ_convert_wrapperÚ_take_2d_multi_object)rrrÚrow_idxÚcol_idxr0r"Úrow_maskÚcol_maskÚ    row_needsÚ    col_needsr=r>r?rrrÚ take_2d_multiãsD
 
 
 
ÿrPé€)ÚmaxsizeÚintznp.dtype)r4Ú    arr_dtypeÚ    out_dtypercCs¾|j|jf}|dkr"t |d¡}n*|dkrL|dkr@t |d¡}n t |d¡}|dk    rX|S|j|jf}|dkrzt |d¡}n*|dkr¤|dkr˜t |d¡}n t |d¡}|dk    rºt||ƒ}|SdS)zê
    Part of _get_take_nd_function below that doesn't need `mask_info` and thus
    can be cached (mask_info potentially contains a numpy ndarray which is not
    hashable and thus cannot be used as argument for cached function).
    r,Nr+r)rGÚ _take_1d_dictrFÚ_take_2d_axis0_dictÚ_take_2d_axis1_dictrH)r4rTrUrÚtupr?rrrÚ_get_take_nd_function_cacheds(        
rZcs@d}|dkrt|||ˆƒ}|dkr<tjfddœ‡‡fdd„ }|S)za
    Get the appropriate "take" implementation for the given dimension, axis
    and dtypes.
    Nr+ÚNone)rcs t|ƒ}t|||ˆ|ˆddS)N)rrr0)r Ú_take_nd_object©rrr>rr/rrr?Wsÿz#_get_take_nd_function.<locals>.func)rZr$Únan)r4rTrUrr0r?rr/rr<Es r<cs(tjfdddddœ‡‡‡‡fdd„ }|S)Nrr[©rrr>rcsjˆdk    r| ˆ¡}ˆdk    r$| ˆ¡}ˆdk    rV|jjdkrD| d¡}n
| d¡}ˆ|ƒ}ˆ||||ddS)NÚmzm8[ns]zM8[ns]©r)Úviewr"r%r&r]©rTÚfÚ    fill_wraprUrrÚwrapperas
 
 
z_view_wrapper.<locals>.wrapper©r$r^)rdrTrUrerfrrcrÚ _view_wrapper`sÿ rhcs$tjfdddddœ‡‡fdd„ }|S)Nrr[r_cs.ˆtkrt|ƒ}| ˆ¡}ˆ||||ddS)Nra)Úobjectrr&r]©Ú
conv_dtyperdrrrfws
z!_convert_wrapper.<locals>.wrapperrg)rdrkrfrrjrrHvsÿ    rH))Úint8rl)rlÚint32)rlÚint64)rlÚfloat64)Úint16rp)rprm)rprn)rpro)rmrm)rmrn)rmro)rnrn)rnro)Úfloat32rq)rqro)roro)riri)rr)rri)údatetime64[ns]rr)útimedelta64[ns]rs)rer[)rrr>rrc    Cs„|dk    r|\}}n|dk}| ¡}|j|jkr:| |j¡}|j|dkrX|j|||d|r€tdƒg|j}|||<||t|ƒ<dS)NrBr)rr>)rDr"r&r1r(Úslicer4r:)    rrr>rrr0r@Ú needs_maskingZ
outindexerrrrr\s
  r\r_cCs¾|\}}|dk    r"|\\}}\}    }
n |dk}|dk}| ¡}    | ¡}
|dk    rr|    r^|||dd…f<|
rr||dd…|f<t|ƒD]>\} } | dkrzt|ƒD]$\} }|dkr’|| |f|| | f<q’qzdS)NrB)rDÚ    enumerate)rrr>rr0rJrKrLrMrNrOÚiZu_ÚjÚvrrrrIs"    rI)rrrr@cCs„d}|s |j|j ¡}}d}nZt|j|ƒ\}}||jkrz|dk    rHd}n|dk}t| ¡ƒ}||f}|sz|j|j ¡}}|||fS)N)NFTrB)r"r2r rrD)rrrrr@r0r"rurrrr34s
 r3)...)...)NTN)rN)NNN)N)~Ú
__future__rÚ    functoolsÚtypingrrrÚnumpyr$Z pandas._libsrZlibalgosrZpandas._typingrr    r
Zpandas.core.dtypes.castr Zpandas.core.dtypes.commonr r Zpandas.core.dtypes.missingrZpandas.core.constructionrZpandas.core.arrays._mixinsrZpandas.core.arrays.baserrr!r)rAr^rPÚ    lru_cacherZr<rhrHZtake_1d_int8_int8Ztake_1d_int8_int32Ztake_1d_int8_int64Ztake_1d_int8_float64Ztake_1d_int16_int16Ztake_1d_int16_int32Ztake_1d_int16_int64Ztake_1d_int16_float64Ztake_1d_int32_int32Ztake_1d_int32_int64Ztake_1d_int32_float64Ztake_1d_int64_int64Ztake_1d_int64_float64Ztake_1d_float32_float32Ztake_1d_float32_float64Ztake_1d_float64_float64Ztake_1d_object_objectZtake_1d_bool_boolZuint8Ztake_1d_bool_objectrnrVZtake_2d_axis0_int8_int8Ztake_2d_axis0_int8_int32Ztake_2d_axis0_int8_int64Ztake_2d_axis0_int8_float64Ztake_2d_axis0_int16_int16Ztake_2d_axis0_int16_int32Ztake_2d_axis0_int16_int64Ztake_2d_axis0_int16_float64Ztake_2d_axis0_int32_int32Ztake_2d_axis0_int32_int64Ztake_2d_axis0_int32_float64Ztake_2d_axis0_int64_int64Ztake_2d_axis0_int64_float64Ztake_2d_axis0_float32_float32Ztake_2d_axis0_float32_float64Ztake_2d_axis0_float64_float64Ztake_2d_axis0_object_objectZtake_2d_axis0_bool_boolZtake_2d_axis0_bool_objectrWZtake_2d_axis1_int8_int8Ztake_2d_axis1_int8_int32Ztake_2d_axis1_int8_int64Ztake_2d_axis1_int8_float64Ztake_2d_axis1_int16_int16Ztake_2d_axis1_int16_int32Ztake_2d_axis1_int16_int64Ztake_2d_axis1_int16_float64Ztake_2d_axis1_int32_int32Ztake_2d_axis1_int32_int64Ztake_2d_axis1_int32_float64Ztake_2d_axis1_int64_int64Ztake_2d_axis1_int64_float64Ztake_2d_axis1_float32_float32Ztake_2d_axis1_float32_float64Ztake_2d_axis1_float64_float64Ztake_2d_axis1_object_objectZtake_2d_axis1_bool_boolZtake_2d_axis1_bool_objectrXZtake_2d_multi_int8_int8Ztake_2d_multi_int8_int32Ztake_2d_multi_int8_int64Ztake_2d_multi_int8_float64Ztake_2d_multi_int16_int16Ztake_2d_multi_int16_int32Ztake_2d_multi_int16_int64Ztake_2d_multi_int16_float64Ztake_2d_multi_int32_int32Ztake_2d_multi_int32_int64Ztake_2d_multi_int32_float64Ztake_2d_multi_int64_int64Ztake_2d_multi_int64_float64Ztake_2d_multi_float32_float32Ztake_2d_multi_float32_float64Ztake_2d_multi_float64_float64Ztake_2d_multi_object_objectZtake_2d_multi_bool_boolZtake_2d_multi_bool_objectrEr\rIr3rrrrÚ<module>sˆ      û
û û>4û=ý<
)û
ÿÿéÿÿÿÿå!ÿÿÿÿå!ÿÿÿÿå!"û