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
U
¬ý°d¹)ã@sVdZddlmZddlZddlmZmZmZmZm    Z    ddl
Z ddl m Z ddlmZddlmZmZddlmZmZdd    lmZmZmZmZmZer°dd
lmZmZmZm Z m!Z!d Z"d d ddœdd„Z#dde"dfdddddddœdd„Z$de"fdddddœdd„Z%d dddd!œd"d#„Z&de"dfd$ddddd%œd&d'„Z'de"dfd(ddddd%œd)d*„Z(dS)+z"
data hash pandas / numpy objects
é)Ú annotationsN)Ú TYPE_CHECKINGÚHashableÚIterableÚIteratorÚcast)Úlib)Úhash_object_array)Ú    ArrayLikeÚnpt)Úis_categorical_dtypeÚ is_list_like)Ú ABCDataFrameÚABCExtensionArrayÚABCIndexÚ ABCMultiIndexÚ    ABCSeries)Ú CategoricalÚ    DataFrameÚIndexÚ
MultiIndexÚSeriesZ0123456789123456zIterator[np.ndarray]Úintznpt.NDArray[np.uint64])ÚarraysÚ    num_itemsÚreturnc    CsÌz t|ƒ}Wn$tk
r0tjgtjdYSXt |g|¡}t d¡}t |¡t d¡}d}t|ƒD]:\}}||}||N}||9}|t d||¡7}|}qj|d|ksºt    dƒ‚|t d¡7}|S)    z¼
    Parameters
    ----------
    arrays : Iterator[np.ndarray]
    num_items : int
 
    Returns
    -------
    np.ndarray[uint64]
 
    Should be the same as CPython's tupleobject.c
    ©ÚdtypeiCBixV4riXBézFed in wrong num_itemsiû|)
ÚnextÚ StopIterationÚnpÚarrayÚuint64Ú    itertoolsÚchainZ
zeros_likeÚ    enumerateÚAssertionError)    rrÚfirstZmultÚoutZlast_iÚiÚaZ    inverse_i©r,úOd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/util/hashing.pyÚcombine_hash_arrays2s" 
r.TÚutf8zIndex | DataFrame | SeriesÚboolÚstrz
str | Noner)ÚobjÚindexÚencodingÚhash_keyÚ
categorizercs€ddlm}ˆdkrt‰tˆtƒr8|tˆˆˆƒdddStˆtƒrptˆjˆˆˆƒj    ddd}||ˆddd}n tˆt
ƒrÜtˆjˆˆˆƒj    ddd}|rȇ‡‡‡fd    d
„d Dƒ}t   |g|¡}    t |    d ƒ}||ˆjddd}n tˆtƒrj‡‡‡fd d
„ˆ ¡Dƒ}
tˆjƒ} |rL‡‡‡‡fdd
„d Dƒ} | d7} t   |
| ¡} dd
„| Dƒ}
t |
| ƒ}||ˆjddd}ntdtˆƒ›ƒ‚|S)a~
    Return a data hash of the Index/Series/DataFrame.
 
    Parameters
    ----------
    obj : Index, Series, or DataFrame
    index : bool, default True
        Include the index in the hash (if Series/DataFrame).
    encoding : str, default 'utf8'
        Encoding for data & key when strings.
    hash_key : str, default _default_hash_key
        Hash_key for string key to encode.
    categorize : bool, default True
        Whether to first categorize object arrays before hashing. This is more
        efficient when the array contains duplicate values.
 
    Returns
    -------
    Series of uint64, same length as the object
    r)rNr#F)rÚcopy©r7)r3rr7c3s$|]}tˆjdˆˆˆdjVqdS©F)r3r4r5r6N©Úhash_pandas_objectr3Ú_values©Ú.0Ú_©r6r4r5r2r,r-Ú    <genexpr>„sùûz%hash_pandas_object.<locals>.<genexpr>©Néc3s"|]\}}t|jˆˆˆƒVqdSrB)Ú
hash_arrayr<)r>r?Zseries)r6r4r5r,r-rA”sÿc3s$|]}tˆjdˆˆˆdjVqdSr9r:r=r@r,r-rAšsùûrcss|]
}|VqdSrBr,)r>Úxr,r,r-rA¨szUnexpected type for hashing )ÚpandasrÚ_default_hash_keyÚ
isinstancerÚ hash_tuplesrrDr<Úastyperr$r%r.r3rÚitemsÚlenÚcolumnsÚ    TypeErrorÚtype)r2r3r4r5r6rÚhZserZ
index_iterrÚhashesrZindex_hash_generatorÚ_hashesr,r@r-r;VsN 
 
ÿ
ÿø
 
 þ
ø
 
r;z+MultiIndex | Iterable[tuple[Hashable, ...]])Úvalsr4r5rcszt|ƒstdƒ‚ddlm‰m}t|tƒs6| |¡‰n|‰‡‡fdd„tˆj    ƒDƒ}‡‡fdd„|Dƒ}t
|t |ƒƒ}|S)a
    Hash an MultiIndex / listlike-of-tuples efficiently.
 
    Parameters
    ----------
    vals : MultiIndex or listlike-of-tuples
    encoding : str, default 'utf8'
    hash_key : str, default _default_hash_key
 
    Returns
    -------
    ndarray[np.uint64] of hashed values
    z'must be convertible to a list-of-tuplesr)rrcs(g|] }ˆˆj|ˆj|ddd‘qS)FT©ZorderedZfastpath)ÚcodesÚlevels)r>Úlevel)rÚmir,r-Ú
<listcomp>Òsÿzhash_tuples.<locals>.<listcomp>c3s|]}t|ˆˆdVqdS)©r4r5N)Ú_hash_categorical)r>ÚcatrZr,r-rAØszhash_tuples.<locals>.<genexpr>) r rNrFrrrHrÚ from_tuplesÚrangeZnlevelsr.rL)rSr4r5rZcat_valsrQrPr,)rr4r5rXr-rI²s
  þ ÿrIr)r\r4r5rcCsdt |jj¡}t|||dd}| ¡}t|ƒr<| |j¡}ntj    t|ƒdd}| 
¡r`t j ||<|S)a
    Hash a Categorical by hashing its categories, and then mapping the codes
    to the hashes
 
    Parameters
    ----------
    cat : Categorical
    encoding : str
    hash_key : str
 
    Returns
    -------
    ndarray[np.uint64] of hashed values, same size as len(c)
    F)r6r#r) r!ZasarrayÚ
categoriesr<rDZisnarLZtakerUÚzerosÚanyrZu8max)r\r4r5ÚvaluesÚhashedÚmaskÚresultr,r,r-r[às    
r[r
)rSr4r5r6rcCs~t|dƒstdƒ‚|j}t|ƒr6td|ƒ}t|||ƒSt|tƒrN| ¡\}}n"t|t    j
ƒsptdt |ƒj ›dƒ‚t ||||ƒS)aK
    Given a 1d array, return an array of deterministic integers.
 
    Parameters
    ----------
    vals : ndarray or ExtensionArray
    encoding : str, default 'utf8'
        Encoding for data & key when strings.
    hash_key : str, default _default_hash_key
        Hash_key for string key to encode.
    categorize : bool, default True
        Whether to first categorize object arrays before hashing. This is more
        efficient when the array contains duplicate values.
 
    Returns
    -------
    ndarray[np.uint64, ndim=1]
        Hashed values, same length as the vals.
    rzmust pass a ndarray-likerz6hash_array requires np.ndarray or ExtensionArray, not z!. Use hash_pandas_object instead.)ÚhasattrrNrr rr[rHrZ_values_for_factorizer!ZndarrayrOÚ__name__Ú _hash_ndarray)rSr4r5r6rr?r,r,r-rDs
 
 
 ÿrDz
np.ndarrayc Csr|j}t |tj¡r4tt |¡ƒdtt |¡ƒS|tkrH| d¡}næt    |j
tj tj fƒrr|  d¡jddd}n¼t    |j
tjƒr¦|jdkr¦|  d|jj›¡ d¡}nˆ|rîdd    lm}m}m}||dd
\}}    ||||    ƒdd d }
t|
||ƒSzt|||ƒ}Wn.tk
r,t| t¡ t¡||ƒ}YnX||d ?N}|t d¡9}||d?N}|t d¡9}||d?N}|S)z!
    See hash_array.__doc__.
    éÚu8Úi8Fr8éÚur)rrÚ    factorize)ÚsortTrTél¹eÉ9´Âz élëb&ì&‚&    é)rr!Z
issubdtypeZ
complex128rDÚrealÚimagr0rJÚ
issubclassrOZ
datetime64Z timedelta64ÚviewÚnumberÚitemsizerFrrrnr[r    rNr1Úobjectr#) rSr4r5r6rrrrnrUr_r\r,r,r-rh9s8       ÿ
   rh))Ú__doc__Ú
__future__rr$ÚtypingrrrrrÚnumpyr!Z pandas._libsrZpandas._libs.hashingr    Zpandas._typingr
r Zpandas.core.dtypes.commonr r Zpandas.core.dtypes.genericrrrrrrFrrrrrrGr.r;rIr[rDrhr,r,r,r-Ú<module>s<   
&û^ý.*ü3ü