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
U
¬ý°d¶6ã@sDddlmZddlmZddlZddlmZddlm    Z    ddl
m Z ddl m Z ddlZddlmZmZdd    lmZdd
lmZmZmZmZdd lmZmZmZejejej ej!ej"ej#ej#d œZ$ej ej%dfej#ej&e    fejej'dfejej'dfej!ej'dfej(ej&d fej"ej)dfiZ*ej'dej%dej&diZ+Gdd„deƒZ,dS)é)Ú annotations)ÚAnyN)Ú infer_dtype)ÚiNaT)ÚNoBufferPresent)Úcache_readonly)Úis_categorical_dtypeÚis_string_dtype)Ú PandasBuffer)ÚColumnÚ ColumnBuffersÚColumnNullTypeÚ    DtypeKind)Ú ArrowCTypesÚ
EndiannessÚdtype_to_arrow_c_fmt)ÚiÚuÚfÚbÚUÚMÚméÿÿÿÿzThis column is non-nullablezThis column uses NaN as nullz!This column uses a sentinel valuec@söeZdZdZd.ddddœdd„Zd    d
œd d „Zed    d
œd d„ƒZedd
œdd„ƒZ    dd
œdd„Z
edd„ƒZ edd„ƒZ ed    d
œdd„ƒZ edd
œdd„ƒZd    d
œdd„Zd/d d!œd"d#„Zd$d
œd%d&„Zd'd
œd(d)„Zd'd
œd*d+„Zd'd
œd,d-„ZdS)0Ú PandasColumnaö
    A column object, with only the methods and properties required by the
    interchange protocol defined.
    A column can contain one or more chunks. Each chunk can contain up to three
    buffers - a data buffer, a mask buffer (depending on null representation),
    and an offsets buffer (if variable-size binary; e.g., variable-length
    strings).
    Note: this Column object can only be produced by ``__dataframe__``, so
          doesn't need its own version or ``__column__`` protocol.
    Tz    pd.SeriesÚboolÚNone)ÚcolumnÚ
allow_copyÚreturncCs0t|tjƒs tdt|ƒ›dƒ‚||_||_dS)zu
        Note: doesn't deal with extension arrays yet, just assume a regular
        Series/ndarray for now.
        zColumns of type ú not handled yetN)Ú
isinstanceÚpdÚSeriesÚNotImplementedErrorÚtypeÚ_colÚ _allow_copy)Úselfrr©r)úUd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/interchange/column.pyÚ__init__Hs zPandasColumn.__init__Úint)rcCs|jjS)z2
        Size of the column, in elements.
        )r&Úsize©r(r)r)r*r-TszPandasColumn.sizecCsdS)z7
        Offset of first element. Always zero.
        rr)r.r)r)r*ÚoffsetZszPandasColumn.offsetztuple[DtypeKind, int, str, str]cCs€|jj}t|ƒr>|jjj}| |j¡\}}}}tj||tj    fSt
|ƒrrt |jƒdkrhtj dt |ƒtj    fStdƒ‚n
| |¡SdS)NÚstringéz.Non-string object dtypes are not supported yet)r&ÚdtyperÚvaluesÚcodesÚ_dtype_from_pandasdtyperÚ CATEGORICALrÚNATIVEr    rÚSTRINGrr$)r(r2r4Ú_ZbitwidthZc_arrow_dtype_f_strr)r)r*r2bs.
 
ûüü
zPandasColumn.dtypecCs>t |jd¡}|dkr&td|›dƒ‚||jdt|ƒ|jfS)z/
        See `self.dtype` for details.
        Nú
Data type z& not supported by interchange protocolr1)Ú    _NP_KINDSÚgetÚkindÚ
ValueErrorÚitemsizerÚ    byteorder)r(r2r=r)r)r*r5€sz$PandasColumn._dtype_from_pandasdtypecCs:|jdtjkstdƒ‚|jjjdtt     |jjj
¡ƒdœS)a:
        If the dtype is categorical, there are two options:
        - There are only values in the data buffer.
        - There is a separate non-categorical Column encoding for categorical values.
 
        Raises TypeError if the dtype is not categorical
 
        Content of returned dict:
            - "is_ordered" : bool, whether the ordering of dictionary indices is
                             semantically meaningful.
            - "is_dictionary" : bool, whether a dictionary-style mapping of
                                categorical values to other objects exists
            - "categories" : Column representing the (implicit) mapping of indices to
                             category values (e.g. an array of cat1, cat2, ...).
                             None if not a dictionary-style categorical.
        rzCdescribe_categorical only works on a column with categorical dtype!T)Z
is_orderedZ is_dictionaryÚ
categories) r2rr6Ú    TypeErrorr&ÚcatZorderedrr"r#rAr.r)r)r*Údescribe_categoricalsÿýz!PandasColumn.describe_categoricalcCsH|jd}zt|\}}Wn$tk
r>td|›dƒ‚YnX||fS)Nrr:z not yet supported)r2Ú_NULL_DESCRIPTIONÚKeyErrorr$)r(r=ÚnullÚvaluer)r)r*Ú describe_null¬s 
zPandasColumn.describe_nullcCs|j ¡ ¡ ¡S)zB
        Number of null elements. Should always be known.
        )r&ZisnaÚsumÚitemr.r)r)r*Ú
null_count¶szPandasColumn.null_countzdict[str, pd.Index]cCs d|jjiS)z8
        Store specific metadata of the column.
        z pandas.index)r&Úindexr.r)r)r*Úmetadata½szPandasColumn.metadatacCsdS)zE
        Return the number of chunks the column consists of.
        ér)r.r)r)r*Ú
num_chunksÄszPandasColumn.num_chunksNz
int | None)Ún_chunksccsr|rh|dkrht|jƒ}||}||dkr2|d7}td|||ƒD]"}t|jj|||…|jƒVqBn|VdS)zy
        Return an iterator yielding the chunks.
        See `DataFrame.get_chunks` for details on ``n_chunks``.
        rOrN)Úlenr&ÚrangerZilocr')r(rQr-ÚstepÚstartr)r)r*Ú
get_chunksÊs 
 ÿ
zPandasColumn.get_chunksr cCs`| ¡dddœ}z| ¡|d<Wntk
r4YnXz| ¡|d<Wntk
rZYnX|S)a`
        Return a dictionary containing the underlying buffers.
        The returned dictionary has the following contents:
            - "data": a two-element tuple whose first element is a buffer
                      containing the data and whose second element is the data
                      buffer's associated dtype.
            - "validity": a two-element tuple whose first element is a buffer
                          containing mask values indicating missing data and
                          whose second element is the mask value buffer's
                          associated dtype. None if the null representation is
                          not a bit or byte mask.
            - "offsets": a two-element tuple whose first element is a buffer
                         containing the offset values for variable-size binary
                         data (e.g., variable-length strings) and whose second
                         element is the offsets buffer's associated dtype. None
                         if the data buffer does not have an associated offsets
                         buffer.
        N)ÚdataÚvalidityÚoffsetsrXrY)Ú_get_data_bufferÚ_get_validity_bufferrÚ_get_offsets_buffer)r(Úbuffersr)r)r*Ú get_buffersÛsýzPandasColumn.get_buffersztuple[PandasBuffer, Any]cCsü|jdtjtjtjtjtjfkr>t|j     ¡|j
d}|j}n¶|jdtj krt|jj j }t||j
d}| |j¡}n€|jdtjkrà|j     ¡}tƒ}|D] }t|tƒr˜| |jdd¡q˜ttj|ddƒ}tjdtjtjf}ntd|jj›d    ƒ‚||fS)
zZ
        Return the buffer containing the data and the buffer's associated dtype.
        r)rúutf-8©ÚencodingZuint8)r2r1r:r )r2rÚINTÚUINTÚFLOATÚBOOLÚDATETIMEr
r&Úto_numpyr'r6r3Ú_codesr5r8Ú    bytearrayr!ÚstrÚextendÚencodeÚnpZ
frombufferrrr7r$)r(Úbufferr2r4ÚbufrÚobjr)r)r*rZs6û
 
 
üzPandasColumn._get_data_bufferc CsÎ|j\}}|jdtjkr’|j ¡}|dk}| }tjt|ƒftj    d}t
|ƒD]\}}t |t ƒrf|n|||<qPt |ƒ}tjdtjtjf}    ||    fSzt|›d}
Wntk
rÀtdƒ‚YnXt|
ƒ‚dS)zÒ
        Return the buffer containing the mask values indicating missing data and
        the buffer's associated dtype.
        Raises NoBufferPresent if null representation is not a bit or byte mask.
        r©Úshaper2r1z! so does not have a separate maskzSee self.describe_nullN)rIr2rr8r&rgrmÚzerosrRZbool_Ú    enumerater!rjr
rerrr7Ú_NO_VALIDITY_BUFFERrFr$r) r(rGÚinvalidroZvalidÚmaskrrprnr2Úmsgr)r)r*r[-s 
 
z!PandasColumn._get_validity_bufferc    Cs¤|jdtjkr”|j ¡}d}tjt|ƒdftjd}t    |ƒD]6\}}t
|t ƒrj|j dd}|t|ƒ7}|||d<q@t |ƒ}tjdtjtjf}ntdƒ‚||fS)a
        Return the buffer containing the offset values for variable-size binary
        data (e.g., variable-length strings) and the buffer's associated dtype.
        Raises NoBufferPresent if the data buffer does not have an associated
        offsets buffer.
        rrOrqr_r`é@zJThis column has a fixed-length dtype so it does not have an offsets buffer)r2rr8r&rgrmrsrRÚint64rtr!rjrlr
rbrZINT64rr7r)    r(r3ÚptrrYrÚvrrnr2r)r)r*r\Ss&
 
  üÿz PandasColumn._get_offsets_buffer)T)N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r+r-Úpropertyr/rr2r5rDrIrLrNrPrVr^rZr[r\r)r)r)r*r<s,  
 
    %-&r)-Ú
__future__rÚtypingrÚnumpyrmZpandas._libs.librZpandas._libs.tslibsrZ pandas.errorsrZpandas.util._decoratorsrZpandasr"Zpandas.api.typesrr    Zpandas.core.interchange.bufferr
Z*pandas.core.interchange.dataframe_protocolr r r rZpandas.core.interchange.utilsrrrrbrcrdrer8rfr;ZUSE_NANZ USE_SENTINELZ NON_NULLABLEr6Z USE_BYTEMASKrErurr)r)r)r*Ú<module>sT       ù öý