hyb
2025-11-10 e0a856b5072c5a09f3f6de6da85abf90e00ee704
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
Ë
nñúh×0ãóà—dZddlmZddlmZddlZddlmZddl    m
Z
ddl m Z ddl mZmZdd    lmZerdd
lmZmZGd „d «Zeegd ¢d¬«Gd„dee««ZGd„dee«Zy)zSparse accessoré)Ú annotations)Ú TYPE_CHECKINGN)Úimport_optional_dependency)Úfind_common_type)Ú SparseDtype)ÚPandasDelegateÚdelegate_names)Ú SparseArray)Ú    DataFrameÚSeriescó —eZdZdZddd„Zd„Zy)Ú BaseAccessorz5Can only use the '.sparse' accessor with Sparse data.Ncó4—||_|j|«y©N)Ú_parentÚ    _validate©ÚselfÚdatas  úUH:\Change_password\venv_build\Lib\site-packages\pandas/core/arrays/sparse/accessor.pyÚ__init__zBaseAccessor.__init__s€ØˆŒ Ø ‰tÕócó—t‚r)ÚNotImplementedErrorrs  rrzBaseAccessor._validate!s€Ü!Ð!rr)ÚreturnÚNone)Ú__name__Ú
__module__Ú __qualname__Ú_validation_msgrr©rrrrs„ØM€Oôó"rr)ÚnpointsÚdensityÚ
fill_valueÚ    sp_valuesÚproperty)ÚtypcóL—eZdZdZd„Zd    d„Zd    d„Zed
d d„«Zd d d„Z    dd„Z
y)ÚSparseAccessorzö
    Accessor for SparseSparse from other sparse matrix data types.
 
    Examples
    --------
    >>> ser = pd.Series([0, 0, 2, 2, 2], dtype="Sparse[int]")
    >>> ser.sparse.density
    0.6
    >>> ser.sparse.sp_values
    array([2, 2, 2])
    cób—t|jt«st|j«‚yr)Ú
isinstanceÚdtyperÚAttributeErrorr rs  rrzSparseAccessor._validate5s&€Ü˜$Ÿ*™*¤kÔ2Ü  ×!5Ñ!5Ó6Ð 6ð3rcóB—t|jj|«Sr)ÚgetattrrÚarray©rÚnameÚargsÚkwargss    rÚ_delegate_property_getz%SparseAccessor._delegate_property_get9s€Üt—|‘|×)Ñ)¨4Ó0Ð0rcój—|dk(r|j|i|¤ŽS|dk(r|j|i|¤ŽSt‚)NÚfrom_cooÚto_coo)r7r8Ú
ValueErrorr1s    rÚ_delegate_methodzSparseAccessor._delegate_method<sD€Ø :Ò Ø 4—=‘= $Ð1¨&Ñ1Ð 1Ø XÒ Ø4—;‘; Ð/¨Ñ/Ð /äÐ rcóp—ddlm}ddlm}|||¬«}||j|j
d¬«}|S)ae
        Create a Series with sparse values from a scipy.sparse.coo_matrix.
 
        Parameters
        ----------
        A : scipy.sparse.coo_matrix
        dense_index : bool, default False
            If False (default), the index consists of only the
            coords of the non-null entries of the original coo_matrix.
            If True, the index consists of the full sorted
            (row, col) coordinates of the coo_matrix.
 
        Returns
        -------
        s : Series
            A Series with sparse values.
 
        Examples
        --------
        >>> from scipy import sparse
 
        >>> A = sparse.coo_matrix(
        ...     ([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])), shape=(3, 4)
        ... )
        >>> A
        <COOrdinate sparse matrix of dtype 'float64'
            with 3 stored elements and shape (3, 4)>
 
        >>> A.todense()
        matrix([[0., 0., 1., 2.],
        [3., 0., 0., 0.],
        [0., 0., 0., 0.]])
 
        >>> ss = pd.Series.sparse.from_coo(A)
        >>> ss
        0  2    1.0
           3    2.0
        1  0    3.0
        dtype: Sparse[float64, nan]
        r©r )Úcoo_to_sparse_series)Ú dense_indexF)ÚindexÚcopy)Úpandasr Ú&pandas.core.arrays.sparse.scipy_sparser=r0r?)ÚclsÚAr>r r=Úresults      rr7zSparseAccessor.from_cooDs2€õT    "ÝOá% a°[ÔAˆÙ˜Ÿ ™ ¨F¯L©L¸uÔEˆàˆ rcóL—ddlm}||j|||¬«\}}}|||fS)aþ
        Create a scipy.sparse.coo_matrix from a Series with MultiIndex.
 
        Use row_levels and column_levels to determine the row and column
        coordinates respectively. row_levels and column_levels are the names
        (labels) or numbers of the levels. {row_levels, column_levels} must be
        a partition of the MultiIndex level names (or numbers).
 
        Parameters
        ----------
        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
        -------
        y : scipy.sparse.coo_matrix
        rows : list (row labels)
        columns : list (column labels)
 
        Examples
        --------
        >>> s = pd.Series([3.0, np.nan, 1.0, 3.0, np.nan, np.nan])
        >>> s.index = pd.MultiIndex.from_tuples(
        ...     [
        ...         (1, 2, "a", 0),
        ...         (1, 2, "a", 1),
        ...         (1, 1, "b", 0),
        ...         (1, 1, "b", 1),
        ...         (2, 1, "b", 0),
        ...         (2, 1, "b", 1)
        ...     ],
        ...     names=["A", "B", "C", "D"],
        ... )
        >>> s
        A  B  C  D
        1  2  a  0    3.0
                 1    NaN
           1  b  0    1.0
                 1    3.0
        2  1  b  0    NaN
                 1    NaN
        dtype: float64
 
        >>> ss = s.astype("Sparse")
        >>> ss
        A  B  C  D
        1  2  a  0    3.0
                 1    NaN
           1  b  0    1.0
                 1    3.0
        2  1  b  0    NaN
                 1    NaN
        dtype: Sparse[float64, nan]
 
        >>> A, rows, columns = ss.sparse.to_coo(
        ...     row_levels=["A", "B"], column_levels=["C", "D"], sort_labels=True
        ... )
        >>> A
        <COOrdinate sparse matrix of dtype 'float64'
            with 3 stored elements and shape (3, 4)>
        >>> A.todense()
        matrix([[0., 0., 1., 3.],
        [3., 0., 0., 0.],
        [0., 0., 0., 0.]])
 
        >>> rows
        [(1, 1), (1, 2), (2, 1)]
        >>> columns
        [('a', 0), ('a', 1), ('b', 0), ('b', 1)]
        r)Úsparse_series_to_coo)Ú sort_labels)rBrGr)rÚ
row_levelsÚ column_levelsrHrGrDÚrowsÚcolumnss        rr8zSparseAccessor.to_coovs6€õV    Pá/Ø L‰L˜* mÀô
шˆ4ð$˜ÐÐrcóº—ddlm}||jjj    «|jj
|jj d¬«S)aà
        Convert a Series from sparse values to dense.
 
        Returns
        -------
        Series:
            A Series with the same values, stored as a dense array.
 
        Examples
        --------
        >>> series = pd.Series(pd.arrays.SparseArray([0, 1, 0]))
        >>> series
        0    0
        1    1
        2    0
        dtype: Sparse[int64, 0]
 
        >>> series.sparse.to_dense()
        0    0
        1    1
        2    0
        dtype: int64
        rr<F)r?r2r@)rAr rr0Úto_denser?r2)rr s  rrNzSparseAccessor.to_denseÈsG€õ0    "áØ L‰L× Ñ × 'Ñ 'Ó )Ø—,‘,×$Ñ$Ø—‘×"Ñ"Øô    
ð    
rN)r2Ústr)F)r>Úboolrr ))r)éF)rHrP)rr ) rrrÚ__doc__rr5r:Ú classmethodr7r8rNr!rrr)r)%s7„ñ
ò7ó1óðó/óð/ôbP ôd
rr)cóZ—eZdZdZd„Zed    d
d„«Zd
d„Zd„Ze    d d„«Z
e d„«Z y) ÚSparseFrameAccessorzÛ
    DataFrame accessor for sparse data.
 
    Examples
    --------
    >>> df = pd.DataFrame({"a": [1, 2, 0, 0],
    ...                   "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
    >>> df.sparse.density
    0.5
    cój—|j}td„|D««st|j«‚y)Nc3ó<K—|]}t|t«–—Œy­wr)r+r)Ú.0Úts  rú    <genexpr>z0SparseFrameAccessor._validate.<locals>.<genexpr>øsèø€Ò>°!”:˜a¤×-Ñ>ùs‚)ÚdtypesÚallr-r )rrr[s   rrzSparseFrameAccessor._validateös/€Ø—‘ˆÜÑ>°vÔ>Ô>Ü  ×!5Ñ!5Ó6Ð 6ð?rNcó—ddlm}ddlm}|j    «}|j |||«\}}|j \}}|j«|j}|j}    |j}
t|
jd«} g} t|«D]P} t|    | |    | dz«}||||d¬«}tj |
||| «}| j#|«ŒR|j$| ||d¬«S)aõ
        Create a new DataFrame from a scipy sparse matrix.
 
        Parameters
        ----------
        data : scipy.sparse.spmatrix
            Must be convertible to csc format.
        index, columns : Index, optional
            Row and column labels to use for the resulting DataFrame.
            Defaults to a RangeIndex.
 
        Returns
        -------
        DataFrame
            Each column of the DataFrame is stored as a
            :class:`arrays.SparseArray`.
 
        Examples
        --------
        >>> import scipy.sparse
        >>> mat = scipy.sparse.eye(3, dtype=float)
        >>> pd.DataFrame.sparse.from_spmatrix(mat)
             0    1    2
        0  1.0    0    0
        1    0  1.0    0
        2    0    0  1.0
        r)ÚIntIndex©r rQF)Úcheck_integrity)rLr?Úverify_integrity)Úpandas._libs.sparser^rAr ÚtocscÚ _prep_indexÚshapeÚ sort_indicesÚindicesÚindptrrrr,ÚrangeÚslicer
Ú _simple_newÚappendÚ _from_arrays)rCrr?rLr^r Ún_rowsÚ    n_columnsrgrhÚ
array_datar,ÚarraysÚiÚslÚidxÚarrs                 rÚ from_spmatrixz!SparseFrameAccessor.from_spmatrixûsû€õ:    1å$àz‰z‹|ˆØŸ™¨¨u°gÓ>‰ˆˆwØ ŸJ™Jш    ð
     ×ÑÔØ—,‘,ˆØ—‘ˆØ—Y‘Yˆ
ܘJ×,Ñ,¨aÓ0ˆØˆÜyÓ!ò    ˆAܐv˜a‘y &¨¨Q©¡-Ó0ˆBÙ˜6 7¨2¡;ÀÔFˆCÜ×)Ñ)¨*°R©.¸#¸uÓEˆCØ M‰M˜#Õ ð        ð
&ˆy×%Ñ%Ø ˜G¨5À5ô
ð    
rcó
—ddlm}|jj«Dcic] \}}||jj «“Œ"}}}|||jj |jj¬«Scc}}w)ay
        Convert a DataFrame with sparse values to dense.
 
        Returns
        -------
        DataFrame
            A DataFrame with the same values stored as dense arrays.
 
        Examples
        --------
        >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0])})
        >>> df.sparse.to_dense()
           A
        0  0
        1  1
        2  0
        rr_)r?rL)rAr rÚitemsr0rNr?rL)rr ÚkÚvrs     rrNzSparseFrameAccessor.to_dense2sf€õ$    %à26·,±,×2DÑ2DÓ2F×G©$¨!¨Q1—7‘7×#Ñ#Ó%Ñ%ÐGˆÑGÙ˜ T§\¡\×%7Ñ%7ÀÇÁ×AUÑAUÔVÐVùóHs¤%A?c    ó.—td«ddlm}t|jj
j ««}t|t«r |j}ggg}}}t|jj««D]¯\}\}}|j}    |    jdk7r td«‚|    jj }
|j#t%j&|t)|
«««|j#|
«|j#|    j*j-|d¬««Œ±t%j.|«}t%j.|«}t%j.|«}||||ff|jj0¬«S)aÁ
        Return the contents of the frame as a sparse SciPy COO matrix.
 
        Returns
        -------
        scipy.sparse.spmatrix
            If the caller is heterogeneous and contains booleans or objects,
            the result will be of dtype=object. See Notes.
 
        Notes
        -----
        The dtype will be the lowest-common-denominator type (implicit
        upcasting); that is to say if the dtypes (even of numeric types)
        are mixed, the one that accommodates all will be chosen.
 
        e.g. If the dtypes are float16 and float32, dtype will be upcast to
        float32. By numpy.find_common_type convention, mixing int64 and
        and uint64 will result in a float64 dtype.
 
        Examples
        --------
        >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
        >>> df.sparse.to_coo()
        <COOrdinate sparse matrix of dtype 'int64'
            with 2 stored elements and shape (4, 1)>
        Úscipyr)Ú
coo_matrixz2fill value must be 0 when converting to COO matrixF)r@)re)rÚ scipy.sparser}rrr[Úto_listr+rÚsubtypeÚ    enumeraterxr0r$r9Úsp_indexrgrlÚnpÚrepeatÚlenr%ÚastypeÚ concatenatere) rr}r,ÚcolsrKrÚcolÚ_ÚserÚsp_arrÚrows            rr8zSparseFrameAccessor.to_cooIs>€ô6    # 7Ô+Ý+ä  §¡×!4Ñ!4×!<Ñ!<Ó!>Ó?ˆÜ eœ[Ô )Ø—M‘MˆEà˜r 2DˆdˆÜ& t§|¡|×'9Ñ'9Ó';Ó<ò    D‰MˆC‘!SØ—Y‘YˆFØ× Ñ  AÒ%Ü Ð!UÓVÐVà—/‘/×)Ñ)ˆCØ K‰KœŸ    ™     #¤s¨3£xÓ0Ô 1Ø K‰K˜Ô Ø K‰K˜×(Ñ(×/Ñ/°¸EÐ/ÓBÕ Cð    Dô~‰~˜dÓ#ˆÜ~‰~˜dÓ#ˆÜ~‰~˜dÓ#ˆÙ˜4 $¨ Ð.°d·l±l×6HÑ6HÔIÐIrcóº—tj|jj«Dcgc]\}}|jj
‘Œc}}«}|Scc}}w)zá
        Ratio of non-sparse points to total (dense) data points.
 
        Examples
        --------
        >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
        >>> df.sparse.density
        0.5
        )rƒÚmeanrrxr0r#)rrŠÚcolumnÚtmps    rr#zSparseFrameAccessor.density{sC€ôg‰g¸T¿\¹\×=OÑ=OÓ=Q×R±    °°6v—|‘|×+Ó+ÓRÓSˆØˆ
ùóSs­ A
có$—ddlm}m}|j\}}|€    ||«}n||«}|€    ||«}n||«}t    |«|k7rt dt    |«›d|›«‚t    |«|k7rt dt    |«›d|›«‚||fS)Nr)Ú default_indexÚ ensure_indexzColumn length mismatch: z vs. zIndex length mismatch: )Úpandas.core.indexes.apir“r”rer…r9)rr?rLr“r”ÚNÚKs       rrdzSparseFrameAccessor._prep_index‰s£€÷    
ð
z‰z‰ˆˆ1Ø ˆ=Ù! !Ó$‰Eá  Ó'ˆEØ ˆ?Ù# AÓ&‰Gá" 7Ó+ˆGä ˆw‹<˜1Ò ÜÐ7¼¸G» °~ÀUÈ1È#ÐNÓOÐ OÜ ˆu‹:˜Š?ÜÐ6´s¸5³z°lÀ%ÈÀsÐKÓLÐ Lؐgˆ~Ðr)NN)rr )rÚfloat) rrrrRrrSrvrNr8r&r#Ú staticmethodrdr!rrrUrUêsV„ñ    ò7ð
ó4
óð4
ólWò.0Jðdò óð ðñóñrrU)rRÚ
__future__rÚtypingrÚnumpyrƒÚpandas.compat._optionalrÚpandas.core.dtypes.castrÚpandas.core.dtypes.dtypesrÚpandas.core.accessorrr    Úpandas.core.arrays.sparse.arrayr
rAr r rr)rUr!rrú<module>r¢stðÙÝ"å ãå>å4Ý1÷õ8á÷÷ "ñ"ñØÒBÈ
ôô
\ >ó
óð
ôDt˜,¨õtr