hyb
2025-12-30 5e753a15ff53faab2261a53367e44d38caf87041
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
Ë
nñúhFã
ób—UddlmZddlZddlZddlmZddlZddlm    Z    ddl
m Z ddl m Z ddlZddlmZmZmZmZmZddlmZmZej4ej6ej8ej:ej<d    œej>ej@ejBejDejFd    œejHejJejLd
œejNe(e(d œiZ)d e*d <ddd„Z+ddd„Z,dd„Z-dd„Z.dd„Z/dd„Z0dd„Z1d d„Z2ddœ                                    d!d„Z3    d                            d"d„Z4y)#é)Ú annotationsN)ÚAny)Úusing_string_dtype)Úimport_optional_dependency)ÚSettingWithCopyError)ÚBufferÚColumnÚColumnNullTypeÚ    DataFrameÚ    DtypeKind)Ú ArrowCTypesÚ
Endianness)ééé é@)rr)érzdict[DtypeKind, dict[int, Any]]Ú
_NP_DTYPEScó€—t|tj«r|St|d«r1    t    dd¬«}    |j |«j | ¬«St|d«s td«‚t|j|¬    «|¬    «S#|j$r}t|«|‚d}~wwxYw#t$rYŒbwxYw)
aH
    Build a ``pd.DataFrame`` from any DataFrame supporting the interchange protocol.
 
    .. note::
 
       For new development, we highly recommend using the Arrow C Data Interface
       alongside the Arrow PyCapsule Interface instead of the interchange protocol.
       From pandas 2.3 onwards, `from_dataframe` uses the PyCapsule Interface,
       only falling back to the interchange protocol if that fails.
 
    .. warning::
 
        Due to severe implementation issues, we recommend only considering using the
        interchange protocol in the following cases:
 
        - converting to pandas: for pandas >= 2.0.3
        - converting from pandas: for pandas >= 3.0.0
 
    Parameters
    ----------
    df : DataFrameXchg
        Object supporting the interchange protocol, i.e. `__dataframe__` method.
    allow_copy : bool, default: True
        Whether to allow copying the memory to perform the conversion
        (if false then zero-copy approach is requested).
 
    Returns
    -------
    pd.DataFrame
 
    Examples
    --------
    >>> df_not_necessarily_pandas = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
    >>> interchange_object = df_not_necessarily_pandas.__dataframe__()
    >>> interchange_object.column_names()
    Index(['A', 'B'], dtype='object')
    >>> df_pandas = (pd.api.interchange.from_dataframe
    ...              (interchange_object.select_columns_by_name(['A'])))
    >>> df_pandas
         A
    0    1
    1    2
 
    These methods (``column_names``, ``select_columns_by_name``) should work
    for any dataframe library which implements the interchange protocol.
    Ú__arrow_c_stream__Úpyarrowz14.0.0)Ú min_version)Úzero_copy_onlyNÚ __dataframe__z#`df` does not support __dataframe__)Ú
allow_copy) Ú
isinstanceÚpdr ÚhasattrrÚtableÚ    to_pandasÚ ArrowInvalidÚ RuntimeErrorÚ ImportErrorÚ
ValueErrorÚ_from_dataframer)ÚdfrÚpaÚes    úYH:\Change_password\venv_build\Lib\site-packages\pandas/core/interchange/from_dataframe.pyÚfrom_dataframer*#sĀô^"”b—l‘lÔ#؈    äˆrÐ'Ô(ð        -Ü+¨IÀ8ÔLˆBð
 -Ø—x‘x “|×-Ñ-À¸^Ð-ÓLÐLô 2Ô 'ÜÐ>Ó?Ð?ä Ø
×Ñ JÐÓ/¸Jô ðøð —?‘?ò -Ü" 1“o¨1Ð,ûð -ûô ò    á ð    ús(ª B1¸!BÂB. B)Â)B.Â1    B=Â<B=cób—g}|j«D]}t|«}|j|«Œ |st|«dkDr t    d«‚|s t|«}n-t|«dk(r|d}nt j |ddd¬«}|jjdd«}|||_    |S)    až
    Build a ``pd.DataFrame`` from the DataFrame interchange object.
 
    Parameters
    ----------
    df : DataFrameXchg
        Object supporting the interchange protocol, i.e. `__dataframe__` method.
    allow_copy : bool, default: True
        Whether to allow copying the memory to perform the conversion
        (if false then zero-copy approach is requested).
 
    Returns
    -------
    pd.DataFrame
    rzHTo join chunks a copy is required which is forbidden by allow_copy=FalserTF)ÚaxisÚ ignore_indexÚcopyz pandas.indexN)
Ú
get_chunksÚprotocol_df_chunk_to_pandasÚappendÚlenr"rÚconcatÚmetadataÚgetÚindex)r&rÚ
pandas_dfsÚchunkÚ    pandas_dfÚ    index_objs      r)r%r%isµ€ð €JØ—‘“ò%ˆÜ/°Ó6ˆ    Ø×ј)Õ$ð%ñ œ#˜j›/¨AÒ-ÜØ Vó
ð    
ñ Ü/°Ó3‰    Ü     ˆZ‹˜AÒ    Ø˜q‘M‰    ä—I‘I˜j¨q¸tÈ%ÔPˆ    à— ‘ —‘ °Ó5€IØÐØ#ˆ    Œà Ðócóê—i}g}|j«D]6}t|t«std|›d«‚||vrtd|›d«‚|j    |«}|j
d}|t jt jt jt jfvrt|«\||<}n~|t jk(rt|«\||<}nY|t jk(rt|«\||<}n4|t j k(rt#|«\||<}nt%d|›d«‚|j'|«Œ9t)j*|«}||j,d<|S)z¡
    Convert interchange protocol chunk to ``pd.DataFrame``.
 
    Parameters
    ----------
    df : DataFrameXchg
 
    Returns
    -------
    pd.DataFrame
    zColumn z is not a stringz is not uniquerz
Data type z not handled yetÚ_INTERCHANGE_PROTOCOL_BUFFERS)Ú column_namesrÚstrr$Úget_column_by_nameÚdtyper ÚINTÚUINTÚFLOATÚBOOLÚprimitive_column_to_ndarrayÚ CATEGORICALÚcategorical_column_to_seriesÚSTRINGÚstring_column_to_ndarrayÚDATETIMEÚdatetime_column_to_ndarrayÚNotImplementedErrorr1rr Úattrs)r&ÚcolumnsÚbuffersÚnameÚcolrAÚbufr9s        r)r0r0sb€ð!€GØ€GØ—‘Ó!óˆÜ˜$¤Ô$ܘw t fÐ,<Ð=Ó>Ð >Ø 7‰?ܘw t f¨NÐ;Ó<Ð <Ø×#Ñ# DÓ)ˆØ—    ‘    ˜!‘ ˆØ Ü M‰MÜ N‰NÜ O‰OÜ N‰Nð    
ñ
ô "=¸SÓ!AÑ ˆGD‰M™3Ø ”i×+Ñ+Ò +Ü!=¸cÓ!BÑ ˆGD‰M™3Ø ”i×&Ñ&Ò &Ü!9¸#Ó!>Ñ ˆGD‰M™3Ø ”i×(Ñ(Ò (Ü!;¸CÓ!@Ñ ˆGD‰M™3ä%¨
°5°'Ð9IÐ&JÓKÐ Kà‰sÖð/ô2— ‘ ˜WÓ%€IØ7>€I‡OOÐ3Ñ4Ø Ðr;có¨—|j«}|d\}}t|||j|j«¬«}t    |||d«}||fS)aJ
    Convert a column holding one of the primitive dtypes to a NumPy array.
 
    A primitive type is one of: int, uint, float, bool.
 
    Parameters
    ----------
    col : Column
 
    Returns
    -------
    tuple
        Tuple of np.ndarray holding the data and the memory owner object
        that keeps the memory alive.
    Údata©ÚoffsetÚlengthÚvalidity)Ú get_buffersÚbuffer_to_ndarrayrWÚsizeÚ    set_nulls)rRrPÚ    data_buffÚ
data_dtyperUs     r)rFrF¼sZ€ð o‰oÓ€Gà# F™OÑ€IˆzÜ Ø: c§j¡j¸¿¹»ô €Dô T˜3 ¨
Ñ 3Ó 4€DØ ˆ=Ðr;cóü—|j}|ds td«‚|d}t|d«r tj|j
«}n td«‚|j «}|d\}}t|||j|j«¬«}t|«dkDr||t|«z}n|}tj|||d    ¬
«}    tj|    «}
t|
||d «}
|
|fS) a
    Convert a column holding categorical data to a pandas Series.
 
    Parameters
    ----------
    col : Column
 
    Returns
    -------
    tuple
        Tuple of pd.Series holding the data and the memory owner object
        that keeps the memory alive.
    Ú is_dictionaryz-Non-dictionary categoricals not supported yetÚ
categoriesÚ_colz}Interchanging categorical columns isn't supported yet, and our fallback of using the `col._col` attribute (a ndarray) failed.rUrVrÚ
is_ordered)rbÚorderedrY)Údescribe_categoricalrMrÚnpÚarrayrcrZr[rWr\r2rÚ CategoricalÚSeriesr]) rRÚ categoricalÚ
cat_columnrbrPÚ
codes_buffÚ codes_dtypeÚcodesÚvaluesÚcatrUs            r)rHrH×s€ð×*Ñ*€Kà Ò 'Ü!Ð"QÓRÐRà˜\Ñ*€J܈z˜6Ô"ô—X‘X˜jŸo™oÓ.‰
ä!ð Mó
ð    
ðo‰oÓ€Gà% f™oÑ€J Ü ØK¨¯
©
¸3¿8¹8»:ô €Eô  ˆ:ƒ˜ÒؘE¤C¨
£OÑ3Ñ4‰àˆä
.‰.ؘ:¨{¸<Ñ/Hô €Cô 9‰9S‹>€Dä T˜3 ¨
Ñ 3Ó 4€DØ ˆ=Ðr;cóv—|j\}}|tjtjtjfvrt |›d«‚|j «}|dsJd«‚|d\}}|jdtjtjfvsJ‚tjdtjtjf}t!||d|j"¬«}|d\}}    t!||    |j$|j'«d    z¬«}
d
} |tjtjfvr;|d } | 4| \} }t!| ||j$|j'«¬«} |dk(r| } d
g|j'«z}t)|j'««D]M}| | |rt*j,||<Œ||
||
|d    z}t/|«}|j1d ¬ «}|||<ŒOt3«rt5j6|d¬«}||fSt+j8|d¬«}||fS)a
    Convert a column holding string data to a NumPy array.
 
    Parameters
    ----------
    col : Column
 
    Returns
    -------
    tuple
        Tuple of np.ndarray holding the data and the memory owner object
        that keeps the memory alive.
    z3 null kind is not yet supported for string columns.Úoffsetsz#String buffers must contain offsetsrUérrrVrNrYzutf-8)Úencodingr?©rAÚobject)Ú describe_nullr
Ú NON_NULLABLEÚ USE_BITMASKÚ USE_BYTEMASKrMrZrAr rIÚ LARGE_STRINGr rCÚUINT8rÚNATIVEr[ÚbufsizerWr\ÚrangergÚnanÚbytesÚdecoderrrjÚasarray)rRÚ    null_kindÚ sentinel_valrPr^Ú_r_rUÚ offset_buffÚ offset_dtypersÚnull_posrYÚ
valid_buffÚ valid_dtypeÚstr_listÚiÚunitsÚ    str_bytesÚstringÚress                     r)rJrJ s^€ð"×/Ñ/Ñ€Iˆ|àÜ×#Ñ#Ü×"Ñ"Ü×#Ñ#ðñô
"؈kÐLÐ Mó
ð    
ðo‰oÓ€Gà 9Ò ÐDÐDÓDÐ à˜6‘?L€Iˆqà 9‰9Q‰<Ü×ÑÜ× Ñ ðñ ðð ô    ‰Ø    Ü×ÑÜ×Ñð    €Jô ˜Y¨
¸1ÀY×EVÑEVÔ W€Dð!(¨    Ñ 2Ñ€Kô Ø\¨#¯*©*¸S¿X¹X»ZÈ!¹^ô€Gð€HØ”^×/Ñ/´×1LÑ1LÐMÑMؘ:Ñ&ˆØ Ð Ø&.Ñ #ˆJ˜ Ü(ؘK°·
±
À3Ç8Á8Ã:ôˆHð˜qÒ Ø$˜9ð+/¨°#·(±(³*Ñ)<€HÜ 3—8‘8“:Ó òˆà Ð  H¨Q¢KÜŸ&™&ˆHQ‰KØ ðW˜Q‘Z '¨!¨a©%¡.Ð1ˆô˜%“Lˆ    ð×!Ñ!¨7Ð!Ó3ˆðˆŠ ð!ô$Ô܏i‰i˜¨Ô.ˆð ˆ<Ðôj‰j˜¨Ô2ˆà ˆ<Ðr;cóz—tjd|«}|r|jd«|jd«}}|dk7r|dz }|jd|›d«}|dk7rGt    j
|«j jd«j j|«}|Stjd    |«}|ro|jd«}|d
k(r3|jtj«d zjd «}|S|d k(r|jd«}|Std|›«‚td|›«‚)z4Parse datetime `format_str` to interpret the `data`.zts([smun]):(.*)rrtÚsz datetime64[ú]ÚÚUTCztd([Dm])ÚDi€Qz datetime64[s]Úmzdatetime64[ms]zDate unit is not supported: z DateTime kind is not supported: ) ÚreÚmatchÚgroupÚastyperrjÚdtÚ tz_localizeÚ
tz_convertrgÚuint64rM)Ú
format_strrUÚtimestamp_metaÚunitÚtzÚ    date_metas      r)Úparse_datetime_format_strr§js9€ô—X‘XÐ0°*Ó=€NÙØ!×'Ñ'¨Ó*¨N×,@Ñ,@ÀÓ,CˆbˆØ 3Š;ð C‰KˆD؏{‰{˜[¨¨¨aÐ0Ó1ˆØ Š8Ü—9‘9˜T“?×%Ñ%×1Ñ1°%Ó8×;Ñ;×FÑFÀrÓJˆD؈ ô—‘˜ jÓ1€IÙØ‰˜qÓ!ˆØ 3Š;ð—K‘K¤§    ¡    Ó*¨lÑ;×CÑCÀOÓTˆDð
ˆ ð    SŠ[Ø—;‘;Ð/Ó0ˆDðˆ ô&Ð(DÀTÀFÐ&KÓLÐ Lô Р@ÀÀ ÐMÓ
NÐNr;c
óD—|j«}|j\}}}}|d\}}t|tj|t t d|›«tjf|j|j«¬«}t||«}t|||d«}||fS)a
    Convert a column holding DateTime data to a NumPy array.
 
    Parameters
    ----------
    col : Column
 
    Returns
    -------
    tuple
        Tuple of np.ndarray holding the data and the memory owner object
        that keeps the memory alive.
    rUrBrVrY) rZrAr[r rBÚgetattrr rr~rWr\r§r])rRrPr‡Ú col_bit_widthr¢ÚdbufrUs       r)rLrL‹s¤€ðo‰oÓ€Gà&)§i¡iÑ#€A€}j !ؐf‰oG€Dˆ!ô Ø ä M‰MØ Ü ”K 3 } oÐ!6Ó 7Ü × Ñ ð        
ð z‰z؏x‰x‹zô
€Dô % Z°Ó 6€DÜ T˜3 ¨
Ñ 3Ó 4€DØ ˆ=Ðr;©rWc    óž—|\}}}}tj|i«j|d«}|€td|›d«‚tjj |«}|dk(rr|€Jd«‚t d«}    |    jj|    j«|d|    j|j|«g|¬«}
tj|
«Stj|j||zdzztj|««} |d    kDr"tjj!| |f¬
«Stj"g|¬ «S) aÚ
    Build a NumPy array from the passed buffer.
 
    Parameters
    ----------
    buffer : Buffer
        Buffer to build a NumPy array from.
    dtype : tuple
        Data type of the buffer conforming protocol dtypes format.
    offset : int, default: 0
        Number of elements to offset from the start of the buffer.
    length : int, optional
        If the buffer is a bit-mask, specifies a number of bits to read
        from the buffer. Has no effect otherwise.
 
    Returns
    -------
    np.ndarray
 
    Notes
    -----
    The returned array doesn't own the memory. The caller of this function is
    responsible for keeping the memory owner object alive as long as
    the returned NumPy array is being used.
    NzConversion for ú is not yet supported.rz1`length` must be specified for a bit-mask buffer.rr¬rr)Úshaperv)rr5rMrgÚ    ctypeslibÚas_ctypes_typerÚ BooleanArrayÚ from_buffersÚbool_Úforeign_bufferÚptrr„ÚctypesÚcastÚPOINTERÚas_arrayrh) ÚbufferrArXrWÚkindÚ    bit_widthr‡Ú column_dtypeÚ ctypes_typer'ÚarrÚ data_pointers             r)r[r[°s:€ð@"Ñ€Dˆ)Q˜ä—>‘> $¨Ó+×/Ñ/°    ¸4Ó@€LØÐÜ! O°E°7Ð:PÐ"QÓRÐRô
—,‘,×-Ñ-¨lÓ;€KàA‚~ØÐ!ÐVÐ#VÓVÐ!Ü '¨    Ó 2ˆØo‰o×*Ñ*Ø H‰H‹JØ Ø 2×$Ñ$ V§Z¡Z°Ó8Ð 9Øð    +ó
ˆô z‰z˜#‹Ðä—{‘{Ø J‰J˜& 9Ñ,°Ñ1Ñ 2´F·N±NÀ;Ó4Oó
ˆ ð AŠ:Ü—<‘<×(Ñ(¨¸f¸YÐ(ÓGÐ G܏x‰x˜ +Ô.Ð.r;có¢—|€|S|j\}}d}|tjk(rtj|«|k(}n’|tj
tj fvr>|sJd«‚|\}}t|||j|j«¬«}|dk(r6|}n2|tjtjfvrntd|›d«‚|/tj|«r|s|j«}    d||<|S|S#t $r|j#t$«}d||<Y|St&$r|j«}d||<Y|SwxYw)aÆ
    Set null values for the data according to the column null kind.
 
    Parameters
    ----------
    data : np.ndarray or pd.Series
        Data to set nulls in.
    col : Column
        Column object that describes the `data`.
    validity : tuple(Buffer, dtype) or None
        The return value of ``col.buffers()``. We do not access the ``col.buffers()``
        here to not take the ownership of the memory of buffer objects.
    allow_modify_inplace : bool, default: True
        Whether to modify the `data` inplace when zero-copy is possible (True) or always
        modify a copy of the `data` (False).
 
    Returns
    -------
    np.ndarray or pd.Series
        Data with the nulls being set.
    Nz/Expected to have a validity buffer for the maskrVrz
Null kind r®)rxr
Ú USE_SENTINELrrjrzr{r[rWr\ryÚUSE_NANrMrgÚanyr.Ú    TypeErrorrÚfloatr)    rUrRrYÚallow_modify_inplacer…r†rŠr‹rŒs             r)r]r]îs`€ð6ÐØˆ Ø!×/Ñ/Ñ€Iˆ|Ø€Hà”N×/Ñ/Ò/Ü—9‘9˜T“? lÑ2‰Ø    ”~×1Ñ1´>×3NÑ3NÐOÑ    OÙÐJÐJÓJˆxØ"*ш
KÜ$Ø ˜ ¨C¯J©J¸s¿x¹x»zô
ˆð ˜1Ò Ø y‰HØ    ”~×2Ñ2´N×4JÑ4JÐKÑ    KØ ä! J¨y¨kÐ9OÐ"PÓQÐQàФ§¡ xÔ 0Ù#Ø—9‘9“;ˆDð     "Ø!ˆD‰Nð €Kˆ4€Køôò    "ð—;‘;œuÓ%ˆDØ!ˆDŠNð €Kô $ò    "à—9‘9“;ˆDØ!ˆDŠNà €Kð     "úsÃ>DÄ#EÄ-EÅ E)T)rÚboolÚreturnú pd.DataFrame)r&Ú DataFrameXchgrrÉ)r&rÌrÊrË)rRr    rÊztuple[np.ndarray, Any])rRr    rÊztuple[pd.Series, Any])rÊzpd.Series | np.ndarray)rRr    rÊz"tuple[np.ndarray | pd.Series, Any])
r»rrAztuple[DtypeKind, int, str, str]rXÚintrWrÍrÊz
np.ndarray)rUznp.ndarray | pd.SeriesrRr    rYz5tuple[Buffer, tuple[DtypeKind, int, str, str]] | NonerÈrÉ)5Ú
__future__rr·ršÚtypingrÚnumpyrgÚpandas._configrÚpandas.compat._optionalrÚ pandas.errorsrÚpandasrÚ*pandas.core.interchange.dataframe_protocolrr    r
r rÌr Úpandas.core.interchange.utilsr rrBÚint8Úint16Úint32Úint64rCÚuint8Úuint16Úuint32r¡rDÚfloat32Úfloat64rErÉrÚ__annotations__r*r%r0rFrHrJr§rLr[r]©r;r)ú<module>râsBðÞ"ã Û    Ýãå-å>Ý.ã÷õ÷ð ‡MMr—w‘w B§H¡H°"·(±(ÀÇÁÑIØ ‡NN˜Ÿ™ b§i¡i°R·Y±YÀBÇIÁIÑNØ ‡OO˜"Ÿ*™*¨"¯*©*Ñ5Ø ‡NN˜ Ñ&ð    /€
Ð +óôCôL$óN)óXó61óh\ó~OóB"ðTñ ;/Ø ð;/à *ð;/ð ð    ;/ð
ð ;/ð ó ;/ðD"&ð    ?Ø
 ð?à    ð?ðDð?ðô    ?r;