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
Ë
nñúh>ãó—dZddlmZddlmZddlmZddlmZddl    m
Z
ddl m Z ddl mZerdd    lmZdd
lZdd
lZdd lmZmZdd „Z    d                            dd „Z            d                            dd„Z            d                                    dd„Z    d                    dd„Zy
)zR
Interaction with scipy.sparse matrices.
 
Currently only includes to_coo helpers.
é)Ú annotations)Ú TYPE_CHECKING)Úlib)Únotna)Ú    factorize)Ú
MultiIndex)ÚSeries)ÚIterableN)Ú
IndexLabelÚnptcóä—t|«}|Dcgc] }t|«‘Œ}}tj|Žt«k7r td«‚tj|Ž|k7r td«‚ycc}w)Nz4Is not a partition because intersection is not null.z2Is not a partition because union is not the whole.)ÚsetÚ intersectionÚ
ValueErrorÚunion)ÚpartsÚwholeÚxs   úYH:\Change_password\venv_build\Lib\site-packages\pandas/core/arrays/sparse/scipy_sparse.pyÚ_check_is_partitionrsj€Ü ‹J€EØ"Ö #˜ŒSVÐ #€EÐ #Ü
×јФ3£5Ò(ÜÐOÓPÐPÜ
‡yy%ИEÒ!ÜÐMÓNÐNð"ùò $sA-cóŠ—|rJt|«dk(r<|jj|d|}|jj|d}n_t    j
|Dcgc]+}|jj |«j«‘Œ-c}«}t||¬«\}}||}|j«}||fScc}w)aö
    For a MultiIndexed sparse Series `ss`, return `ax_coords` and `ax_labels`,
    where `ax_coords` are the coordinates along one of the two axes of the
    destination sparse matrix, and `ax_labels` are the labels from `ss`' Index
    which correspond to these coordinates.
 
    Parameters
    ----------
    ss : Series
    levels : tuple/list
    valid_ilocs : numpy.ndarray
        Array of integer positions of valid values for the sparse matrix in ss.
    sort_labels : bool, default False
        Sort the axis labels before forming the sparse matrix. When `levels`
        refers to a single level, set to True for a faster execution.
 
    Returns
    -------
    ax_coords : numpy.ndarray (axis coordinates)
    ax_labels : list (axis labels)
    ér)Úsort)
ÚlenÚindexÚcodesÚlevelsrÚfast_zipÚget_level_valuesÚto_numpyrÚtolist)    ÚssrÚ valid_ilocsÚ sort_labelsÚ    ax_coordsÚ    ax_labelsÚlvlÚ levels_valuesrs             rÚ_levels_to_axisr)'sµ€ñ<”s˜6“{ aÒ'Ø—H‘H—N‘N 6¨!¡9Ñ-¨kÑ:ˆ    Ø—H‘H—O‘O F¨1¡IÑ.‰    ôŸ ™ ØBHÖ I¸3ˆRX‰X× &Ñ & sÓ +× 4Ñ 4Õ 6Ò Ió
ˆ ô% ]¸ÔEшˆyؘ+Ñ&ˆ    à× Ñ Ó"€IØ iÐ Ðùò JsÁ 0Ccó@—t||gt|jj««|jj
}t |«}||}|jjj|}t||||¬«\}}    t||||¬«\}
} |||
|    | fS)a‡
    For an arbitrary MultiIndexed sparse Series return (v, i, j, ilabels,
    jlabels) where (v, (i, j)) is suitable for passing to scipy.sparse.coo
    constructor, and ilabels and jlabels are the row and column labels
    respectively.
 
    Parameters
    ----------
    ss : Series
    row_levels : tuple/list
    column_levels : tuple/list
    sort_labels : bool, default False
        Sort the row and column labels before forming the sparse matrix.
        When `row_levels` and/or `column_levels` refer to a single level,
        set to `True` for a faster execution.
 
    Returns
    -------
    values : numpy.ndarray
        Valid values to populate a sparse matrix, extracted from
        ss.
    i_coords : numpy.ndarray (row coordinates of the values)
    j_coords : numpy.ndarray (column coordinates of the values)
    i_labels : list (row labels)
    j_labels : list (column labels)
    )r$)
rÚrangerÚnlevelsÚarrayÚ    sp_valuesrÚsp_indexÚindicesr)) r"Ú
row_levelsÚ column_levelsr$Úsp_valsÚna_maskÚvaluesr#Úi_coordsÚi_labelsÚj_coordsÚj_labelss             rÚ_to_ijvr:Ts¦€ôN˜ ]Ð3´U¸2¿8¹8×;KÑ;KÓ5LÔMðh‰h× Ñ €GܐG‹n€GØ WÑ €FØ—(‘(×#Ñ#×+Ñ+¨GÑ4€Kä(Ø
ˆJ˜ °ôÑ€Hˆhô)Ø
ˆM˜;°KôÑ€Hˆhð 8˜X x°Ð 9Ð9ócóæ—ddl}|jjdkr td«‚|jjs td«‚|Dcgc]}|jj |«‘Œ}}|Dcgc]}|jj |«‘Œ}}t ||||¬«\}}}}    }
|jj|||fft|    «t|
«f¬«} | |    |
fScc}wcc}w)zÐ
    Convert a sparse Series to a scipy.sparse.coo_matrix using index
    levels row_levels, column_levels as the row and column
    labels respectively. Returns the sparse_matrix, row and column labels.
    rNéz-to_coo requires MultiIndex with nlevels >= 2.zADuplicate index entries are not allowed in to_coo transformation.)r1r2r$)Úshape)
Ú scipy.sparserr,rÚ    is_uniqueÚ_get_level_numberr:ÚsparseÚ
coo_matrixr) r"r1r2r$ÚscipyrÚvÚiÚjÚrowsÚcolumnsÚ sparse_matrixs             rÚsparse_series_to_coorKŽsô€óà    ‡xx×ј!ÒÜÐHÓIÐIØ 8‰8× Ò ÜØ Oó
ð    
ð
:DÖD°A"—(‘(×,Ñ,¨QÕ/ÐD€JÐDØ<IÖJ°qR—X‘X×/Ñ/°Õ2ÐJ€MÐJä$Ø
z°ÈKôÑ€A€qˆ!ˆT7ð—L‘L×+Ñ+Ø    
ˆQˆFˆ œC ›I¤s¨7£|Ð4ð,ó€Mð ˜$ Ð 'Ð'ùòEùÚJs Á"C)Á6"C.cóÜ—ddlm}    t|jt    j
|j |jf«d¬«}|j«}|j||j««}|r<t    j|j |jg«}|j!|«}|S#t$r(}tdt|«j›d«|‚d}~wwxYw)a
    Convert a scipy.sparse.coo_matrix to a Series with type sparse.
 
    Parameters
    ----------
    A : scipy.sparse.coo_matrix
    dense_index : bool, default False
 
    Returns
    -------
    Series
 
    Raises
    ------
    TypeError if A is not a coo_matrix
    r)Ú SparseDtypeF)ÚcopyzExpected coo_matrix. Got z     instead.N)ÚpandasrMr    ÚdatarÚ from_arraysÚrowÚcolÚAttributeErrorÚ    TypeErrorÚtypeÚ__name__Ú
sort_indexÚastypeÚdtypeÚ from_productÚreindex)ÚAÚ dense_indexrMÚserÚerrÚinds      rÚcoo_to_sparse_seriesrb¯sŀõ&#ðܐQ—V‘VœZ×3Ñ3°Q·U±U¸A¿E¹E°NÓCÈ%ÔPˆð
.‰.Ó
€CØ
*‰*‘[ §¡Ó+Ó
,€CÙÜ×%Ñ% q§u¡u¨a¯e©e nÓ5ˆØk‰k˜#ÓˆØ €Jøô òÜØ'¬¨Q«×(8Ñ(8Ð'9¸Ð Có
àð    ûðúsˆAB:Â:    C+Ã#C&Ã&C+)rr
rr
)F)rútuple[int] | list[int]r#znpt.NDArray[np.intp]r$ÚboolÚreturnz-tuple[npt.NDArray[np.intp], list[IndexLabel]]))r)rF)r1rcr2rcr$rdrezatuple[np.ndarray, npt.NDArray[np.intp], npt.NDArray[np.intp], list[IndexLabel], list[IndexLabel]])
r"r    r1ú Iterable[int]r2rfr$rdrezBtuple[scipy.sparse.coo_matrix, list[IndexLabel], list[IndexLabel]])r]zscipy.sparse.coo_matrixr^rdrer    )Ú__doc__Ú
__future__rÚtypingrÚ pandas._libsrÚpandas.core.dtypes.missingrÚpandas.core.algorithmsrÚpandas.core.indexes.apirÚpandas.core.seriesr    Úcollections.abcr
ÚnumpyÚnpr?rDÚpandas._typingr r rr)r:rKrb©r;rú<module>rtsðñõ
#å åå,å,Ý.Ý%áÝ(ãÛ÷ó Oðð    * à "ð* ð&ð* ðð    * ð
3ó * ð^*.Ø,0Øð    7:à&ð7:ð*ð7:ðð    7:ð
ó 7:ðx!%Ø#'Øð    (Øð(àð(ð!ð(ðð    (ð
Hó (ðD5:ð Øð Ø-1ð à ô r;