
    I jF                    @   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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%  \ RL                  \ RN                  \ RP                  \ RR                  \ RT                  \ RV                  \ RV                  S.r,\ RP                  \RZ                  S4\ RV                  \R\                  \4\ RL                  \R^                  S4\ RN                  \R^                  S4\ RR                  \R^                  S4\ R`                  \R\                  S4\ RT                  \Rb                  S 40r2\R^                  S\RZ                  S\R\                  S0r3 " S S\5      r4g)    )annotations)TYPE_CHECKINGAnyN)using_python_scalars)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)PandasColumnJ   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      o/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/pandas/core/interchange/column.py__init__PandasColumn.__init__V   sw    
 fbll++ !..) *22  &")),,%(8fFV&WXX 	%    c                .    U R                   R                  $ )z"
Size of the column, in elements.
)r.   sizer0   s    r3   r8   PandasColumn.sizej   s     yy~~r6   c                    g)z'
Offset of first element. Always zero.
r    r9   s    r3   offsetPandasColumn.offsetp   s     r6   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,   )r0   rC   rF   _bitwidthc_arrow_dtype_f_strs         r3   rC   PandasColumn.dtypex   s    		eR0011II$$**E ,,U[[9# %%#!!	  U##499%)<<$$(/%%	  &&VWW//66r6   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]rB   )	_NP_KINDSgetkind
ValueErrorr&   r   numpy_dtype	byteorderr   baser   itemsizer   BOOLr   )r0   rC   rS   rV   s       r3   rG   $PandasColumn._dtype_from_pandasdtype   s     }}UZZ.<z%0VWXXeZ(())33I//

,,I//))33IIO#   	  ^^a')=e)DiOOr6   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)rC   r   rH   r)   r.   catorderedr"   r'   r+   r^   r9   s    r3   describe_categorical!PandasColumn.describe_categorical   si    $ zz!}	 5 55U 
 ))--//!&ryy1I1I'JK
 	
r6   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  n[        SU S35      UeS nAff = f)N   r   rP   z not yet supported)r&   r.   rC   r   r   USE_BYTEMASKr   array	_pa_arraychunksbuffersNON_NULLABLEUSE_BITMASK_NULL_DESCRIPTIONKeyErrorr,   )r0   column_null_dtype
null_valuerS   nullvalueerrs          r3   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!}	V+D1KD {  	V%
4&8J&KLRUU	Vs   C) )
D3DDc                    U R                   R                  5       R                  5       n[        5       (       d  UR	                  5       nU$ )z2
Number of null elements. Should always be known.
)r.   isnasumr   item)r0   results     r3   
null_countPandasColumn.null_count   s6    
 !%%'#%%[[]Fr6   c                2    SU R                   R                  0$ )z(
Store specific metadata of the column.
zpandas.index)r.   indexr9   s    r3   metadataPandasColumn.metadata   s    
 		00r6   c                    g)z5
Return the number of chunks the column consists of.
rd   r<   r9   s    r3   
num_chunksPandasColumn.num_chunks   s     r6   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``.
rd   r   N)lenr.   ranger"   ilocr/   )r0   n_chunksr8   stepstarts        r3   
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)r0   ri   s     r3   get_buffersPandasColumn.get_buffers  s    ( ))+"
	"&";";"=GJ	!%!9!9!;GI   		
  		s    ? A 
AA
AAc                   U R                   S   [        R                  :X  a  [        U R                   S   5      S:  a4  U R                  R
                  R                  S5      R                  5       nOU R                  R                  5       n[        XR                  S9n[        R                  S[        R                  [        R                  4nX#4$ U R                   S   [        R                  [        R                  [        R                   [        R"                  4;   a  U R                   nU R                  R$                  n['        U R                  R                   [(        5      (       a@  UR*                  R,                  S   n[/        UR1                  5       S   [        U5      S9nX#4$ ['        U R                  R                   [2        5      (       a  UR4                  nOUR6                  n[        XR                  S9nX#4$ U R                   S   [        R8                  :X  aQ  U R                  R:                  R<                  n[        XPR                  S9nU R?                  UR                   5      nX#4$ U R                   S   [        R@                  :X  a  U R                  R                  5       n[C        5       nU H8  n['        U[D        5      (       d  M  URG                  URI                  S	S
95        M:     [        [J        RL                  " USS95      n[        R                  S[        RN                  [        R                  4nX#4$ [Q        SU R                  R                    S35      e)zJ
Return the buffer containing the data and the buffer's associated dtype.
r         N)r2   @   rd   lengthutf-8encodinguint8)rC   rB   rP   r%   ))rC   r   DATETIMEr   r.   dt
tz_convertto_numpyr   r/   INTr   INT64r   rI   UINTFLOATrY   rf   r&   r   rg   rh   r   ri   r   _data_ndarrayrH   rE   _codesrG   rJ   	bytearraystrextendencodenp
frombufferUINT8r,   )	r0   np_arrbufferrC   arrrF   bufr   objs	            r3   r   PandasColumn._get_data_buffer5  s    ::a=I... 4::a=!A%006??A++-!&5E5EFF!!!!	Et }i ZZ]MMNNOONN	
 
 JJE))//C$))//:66 mm**1-,KKM!$s8 }$$))//?;;!&5E5EFF> }= ZZ]i333II$$++E!%4D4DEF00=E6 }5 ZZ]i...))$$&CA c3''HHSZZZ9:  ""--"ABF !!!!	E } &
499??2CCS&TUUr6   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  n[9        S5      UeSnAf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   rd   Nr   rB   shaperC   z! so does not have a separate maskzSee self.describe_null)rs   r&   r.   rC   r   rf   rg   rh   r   rY   r   r   rI   ri   r   r   r   _maskr   rJ   r   r   zerosbool_	enumerater   _NO_VALIDITY_BUFFERrm   r,   r	   )r0   rp   invalidr   rC   r   maskr   validr   r   msgrr   s                r3   r   !PandasColumn._get_validity_buffer  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= 	I(.//PQC
 c""	  	I%&>?SH	Is   :I 
I,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   rd   r   r   r   r   zJThis column has a fixed-length dtype so it does not have an offsets buffer)rC   r   rJ   r.   r   r   r   r   int64r   r&   r   r   r   r   r   r   r   rI   r	   )	r0   rE   ptrr   r   vr   r   rC   s	            r3   r    PandasColumn._get_offsets_buffer  s     ::a=I,,,YY'')FChhc&kAo%7rxxHG!&) a%%'2A3q6MC!$A * "'*F !!!!	E } "5 r6   )r/   r.   )T)r1   z	pd.Seriesr2   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__r4   r8   propertyr=   r
   rC   rG   ra   rs   rz   r~   r   r   r   r   r   r   __static_attributes__r<   r6   r3   r"   r"   J   s    	&(   7 7:PB 
 
8  &   1 1"#JI	7IV7#r&r6   r"   )5
__future__r   typingr   r   numpyr   pandas._configr   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   rY   rJ   r   rQ   USE_NANUSE_SENTINELrj   rH   re   rl   r   r"   r<   r6   r3   <module>r      sl   "
  / ( $ ) 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 U6 Ur6   