
    MhD                    4   S SK Jr  S SKJrJr  S SKrS SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S SKrS S	KJrJr  S S
KJr  S SKJrJr  S SKJrJrJrJr  S SKJ r J!r!J"r"  \(       a  S SKJ#r#  \RH                  \RJ                  \RL                  \RN                  \RP                  \RR                  \RR                  S.r*\RL                  \RV                  S4\RR                  \RX                  \
4\RH                  \RZ                  S4\RJ                  \RZ                  S4\RN                  \RZ                  S4\R\                  \RX                  S4\RP                  \R^                  S 40r0\RZ                  S\RV                  S\RX                  S0r1 " S S\5      r2g)    )annotations)TYPE_CHECKINGAnyN)infer_dtype)iNaT)NoBufferPresent)cache_readonly)BaseMaskedDtype)
ArrowDtypeDatetimeTZDtype)is_string_dtype)PandasBufferPandasBufferPyarrow)ColumnColumnBuffersColumnNullType	DtypeKind)ArrowCTypes
Endiannessdtype_to_arrow_c_fmt)Buffer)iufbUMmzThis column is non-nullablezThis column uses NaN as nullz!This column uses a sentinel valuec                      \ rS rSrSrSSS jjrSS jr\SS j5       r\	SS j5       r
SS jr\S 5       r\S	 5       r\	SS
 j5       r\SS j5       rSS jrSSS jjrSS jr  SS jrSS jrSS jrSrg)PandasColumnH   a  
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.
c                    [        U[        R                  5      (       a  [        SUR                   S35      e[        U[        R
                  5      (       d  [        S[        U5       S35      eXl        X l	        g)z]
Note: doesn't deal with extension arrays yet, just assume a regular
Series/ndarray for now.
zExpected a Series, got a DataFrame. This likely happened because you called __dataframe__ on a DataFrame which, after converting column names to string, resulted in duplicated names: zD. Please rename these columns before using the interchange protocol.zColumns of type  not handled yetN)

isinstancepd	DataFrame	TypeErrorcolumnsSeriesNotImplementedErrortype_col_allow_copy)selfcolumn
allow_copys      P/var/www/html/env/lib/python3.13/site-packages/pandas/core/interchange/column.py__init__PandasColumn.__init__T   sw    
 fbll++ !..) *22  &")),,%(8fFV&WXX 	%    c                .    U R                   R                  $ )z"
Size of the column, in elements.
)r-   sizer/   s    r2   r7   PandasColumn.sizeh   s     yy~~r5   c                    g)z'
Offset of first element. Always zero.
r    r8   s    r2   offsetPandasColumn.offsetn   s     r5   c                   U R                   R                  n[        U[        R                  5      (       ab  U R                   R
                  R                  nU R                  UR                  5      u  nnnn[        R                  UU[        R                  4$ [        U5      (       aO  [        U R                   5      S;   a+  [        R                  S[        U5      [        R                  4$ [!        S5      eU R                  U5      $ )N)stringempty   z.Non-string object dtypes are not supported yet)r-   dtyper%   r&   CategoricalDtypevaluescodes_dtype_from_pandasdtyper   CATEGORICALr   NATIVEr   r   STRINGr   r+   )r/   rB   rE   _bitwidthc_arrow_dtype_f_strs         r2   rB   PandasColumn.dtypev   s    		eR0011II$$**E ,,U[[9# %%#!!	  U##499%)<<$$(/%%	  &&VWW//66r5   c                   [         R                  UR                  S5      nUc  [        SU S35      e[	        U[
        5      (       a  UR                  R                  nOd[	        U[        5      (       a  UR                  R                  nO8[	        U[        5      (       a  UR                  R                  nOUR                  nUS:X  a  UUR                  [        R                  U4$ X!R                  S-  [        U5      U4$ )z
See `self.dtype` for details.
N
Data type z& not supported by interchange protocolzbool[pyarrow]rA   )	_NP_KINDSgetkind
ValueErrorr%   r   numpy_dtype	byteorderr   baser
   itemsizer   BOOLr   )r/   rB   rR   rU   s       r2   rF   $PandasColumn._dtype_from_pandasdtype   s     }}UZZ.<z%0VWXXeZ(())33I//

,,I//))33IIO#   	  ^^a')=e)DiOOr5   c                   U R                   S   [        R                  :X  d  [        S5      eU R                  R
                  R                  S[        [        R                  " U R                  R
                  R                  5      5      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.
r   zCdescribe_categorical only works on a column with categorical dtype!T)
is_orderedis_dictionary
categories)rB   r   rG   r(   r-   catorderedr!   r&   r*   r]   r8   s    r2   describe_categorical!PandasColumn.describe_categorical   si    $ zz!}	 5 55U 
 ))--//!&ryy1I1I'JK
 	
r5   c                   [        U R                  R                  [        5      (       a  [        R
                  nSnX4$ [        U R                  R                  [        5      (       ac  U R                  R                  R                  R                  S   R                  5       S   c  [        R                  S 4$ [        R                  S4$ U R                  S   n [        U   u  pEXE4$ ! [         a    [        SU S35      ef = f)N   r   rO   z not yet supported)r%   r-   rB   r
   r   USE_BYTEMASKr   array	_pa_arraychunksbuffersNON_NULLABLEUSE_BITMASK_NULL_DESCRIPTIONKeyErrorr+   )r/   column_null_dtype
null_valuerR   nullvalues         r2   describe_nullPandasColumn.describe_null   s    diioo77 . ; ;J$00diiooz22 yy((//2::<Q?G%22D88!--q00zz!}	M+D1KD {  	M%
4&8J&KLL	Ms   C) )Dc                n    U R                   R                  5       R                  5       R                  5       $ )z2
Number of null elements. Should always be known.
)r-   isnasumitemr8   s    r2   
null_countPandasColumn.null_count   s'    
 yy~~##%**,,r5   c                2    SU R                   R                  0$ )z(
Store specific metadata of the column.
zpandas.index)r-   indexr8   s    r2   metadataPandasColumn.metadata   s    
 		00r5   c                    g)z5
Return the number of chunks the column consists of.
rc   r;   r8   s    r2   
num_chunksPandasColumn.num_chunks   s     r5   Nc              #  
  #    U(       at  US:  an  [        U R                  5      nX!-  nX!-  S:w  a  US-  n[        SX1-  U5       H4  n[        U R                  R                  XDU-    U R
                  5      v   M6     gU v   g7f)za
Return an iterator yielding the chunks.
See `DataFrame.get_chunks` for details on ``n_chunks``.
rc   r   N)lenr-   ranger!   ilocr.   )r/   n_chunksr7   stepstarts        r2   
get_chunksPandasColumn.get_chunks   s}     
 1tyy>D#D!#	q$/48"IINN54<8$:J:J  9
 Js   BBc                    U R                  5       SSS.n U R                  5       US'    U R                  5       US'   U$ ! [         a     N"f = f! [         a     U$ f = f)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offsetsr   r   )_get_data_buffer_get_validity_bufferr   _get_offsets_buffer)r/   rh   s     r2   get_buffersPandasColumn.get_buffers  s    ( ))+"
	"&";";"=GJ	!%!9!9!;GI   		
  		s    ? A 
AA
AAc                   U R                   S   [        R                  [        R                  [        R                  [        R
                  [        R                  4;   GaT  U R                   nU R                   S   [        R                  :X  aP  [        U R                   S   5      S:  a4  U R                  R                  R                  S5      R                  5       nOU R                  R                  n[        U R                  R                   [        5      (       a  UR                  nOu[        U R                  R                   [         5      (       a@  UR"                  R$                  S   n['        UR)                  5       S   [        U5      S9nXA4$ UR*                  n[-        X R.                  S9nXA4$ U R                   S   [        R0                  :X  aQ  U R                  R2                  R4                  n[-        XPR.                  S9nU R7                  UR                   5      nXA4$ U R                   S   [        R8                  :X  a  U R                  R                  5       n[;        5       nU H8  n[        U[<        5      (       d  M  UR?                  URA                  SS	95        M:     [-        [B        RD                  " US
S95      nU R                   nXA4$ [G        SU R                  R                    S35      e)zJ
Return the buffer containing the data and the buffer's associated dtype.
r         Nrc   length)r1   utf-8encodinguint8)rB   rO   r$   )$rB   r   INTUINTFLOATrX   DATETIMEr   r-   dt
tz_convertto_numpyre   r%   r
   _datar   rf   rg   r   rh   _ndarrayr   r.   rG   rD   _codesrF   rI   	bytearraystrextendencodenp
frombufferr+   )	r/   rB   np_arrarrbufferrE   bufr   objs	            r2   r   PandasColumn._get_data_buffer0  s>    ::a=MMNNOONN
 
 JJEzz!}	 2 22s4::a=7IA7M006??Aiioodiioo?? YYF		<< --..q1C0a("3xF "=( \\F!&5E5EFF4 }3 ZZ]i333II$$++E!%4D4DEF00=E, }+ ZZ]i...))$$&CA c3''HHSZZZ9:  ""--"ABF
 JJE } &
499??2CCS&TUUr5   c                   U R                   u  p[        U R                  R                  [        5      (       a  U R                  R
                  R                  R                  S   n[        R                  S[        R                  [        R                  4nUR                  5       S   c  g[        UR                  5       S   [        U5      S9nXT4$ [        U R                  R                  [         5      (       a^  U R                  R
                  R"                  n[%        U5      n[        R                  S[        R                  [        R                  4nXT4$ U R                  S   [        R&                  :X  a  U R                  R)                  5       nUS:H  nU(       + n[*        R,                  " [        U5      4[*        R.                  S9n[1        U5       H   u  p[        U
[2        5      (       a  UOUXi'   M"     [%        U5      n[        R                  S[        R                  [        R                  4nXT4$  [4        U    S3n[;        U5      e! [6         a    [9        S5      ef = f)	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   rc   Nr   rA   shaperB   z! so does not have a separate maskzSee self.describe_null)rq   r%   r-   rB   r   re   rf   rg   r   rX   r   r   rH   rh   r   r   r
   _maskr   rI   r   r   zerosbool_	enumerater   _NO_VALIDITY_BUFFERrl   r+   r   )r/   ro   invalidr   rB   r   maskr   validr   r   msgs               r2   r   !PandasColumn._get_validity_buffern  s    **diiooz22 ))//++2215C^^Q(8(8*:K:KLE{{}Q'(a 3xF = diioo7799??((D!$'F^^Q(8(8*:K:KLE= ::a=I,,, ))$$&C qLEiG883s8+RXX>D#C.#-c3#7#7%W )
 "$'F ^^Q(8(8*:K:KLE= 	@(.//PQC
 c""	  	@%&>??	@s   :I I'c                   U R                   S   [        R                  :X  a  U R                  R	                  5       nSn[
        R                  " [        U5      S-   4[
        R                  S9n[        U5       H>  u  pE[        U[        5      (       a  UR                  SS9nU[        U5      -  nX#US-   '   M@     [        U5      n[        R                  S[        R                   ["        R$                  4nXx4$ ['        S5      e)z
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.
r   rc   r   r   r   @   zJThis column has a fixed-length dtype so it does not have an offsets buffer)rB   r   rI   r-   r   r   r   r   int64r   r%   r   r   r   r   r   INT64r   rH   r   )	r/   rD   ptrr   r   vr   r   rB   s	            r2   r    PandasColumn._get_offsets_buffer  s     ::a=I,,,YY'')FChhc&kAo%7rxxHG!&) a%%'2A3q6MC!$A * "'*F !!!!	E } "5 r5   )r.   r-   )T)r0   z	pd.Seriesr1   boolreturnNone)r   int)r   ztuple[DtypeKind, int, str, str])r   zdict[str, pd.Index])N)r   z
int | None)r   r   )r   z.tuple[Buffer, tuple[DtypeKind, int, str, str]])r   ztuple[Buffer, Any] | None)r   ztuple[PandasBuffer, Any])__name__
__module____qualname____firstlineno____doc__r3   r7   propertyr<   r	   rB   rF   r`   rq   rw   r{   r~   r   r   r   r   r   __static_attributes__r;   r5   r2   r!   r!   H   s    	&(   7 7:PB 
 
8  & - - 1 1"#J<	7<|7#r&r5   r!   )3
__future__r   typingr   r   numpyr   pandas._libs.libr   pandas._libs.tslibsr   pandas.errorsr   pandas.util._decoratorsr	   pandas.core.dtypes.dtypesr
   pandasr&   r   r   pandas.api.typesr   pandas.core.interchange.bufferr   r   *pandas.core.interchange.dataframe_protocolr   r   r   r   pandas.core.interchange.utilsr   r   r   r   r   r   r   rX   rI   r   rP   USE_NANUSE_SENTINELri   rG   rd   rk   r   r!   r;   r5   r2   <module>r      si   "
  ( $ ) 2 5  -   A 
													 OOn,,d344d;MMN//6NN^00$7NN^00$7 N77<~22A6  !>:!D E6 Er5   