Ë
    AúYjŽF  ã                  ó6  — d dl mZ d dlmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d dlZd d
lmZmZ d dlmZ d dlmZmZ d dlmZmZmZm Z  d dl!m"Z"m#Z#m$Z$ erd dlm%Z% e jL                  e jN                  e jP                  e jR                  e jT                  e jV                  e jV                  dœZ,e jP                  ejZ                  dfe jV                  ej\                  efe jL                  ej^                  dfe jN                  ej^                  dfe jR                  ej^                  dfe j`                  ej\                  dfe jT                  ejb                  d fiZ2ej^                  dejZ                  dej\                  diZ3 G d„ de«      Z4y)é    )Ú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ÚméÿÿÿÿzThis column is non-nullablezThis column uses NaN as nullz!This column uses a sentinel valuec                  óÈ   — e Zd ZdZddd„Zdd„Zedd„«       Zedd„«       Z	dd„Z
ed„ «       Zed„ «       Zedd	„«       Zedd
„«       Zdd„Zddd„Zdd„Z	 	 dd„Zdd„Zdd„Zy)Ú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.
    c                óê   — t        |t        j                  «      rt        d|j                  › d�«      ‚t        |t        j
                  «      st        dt        |«      › d�«      ‚|| _        || _	        y)zu
        Note: doesn't deal with extension arrays yet, just assume a regular
        Series/ndarray for now.
        z·Expected 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      úi/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/pandas/core/interchange/column.pyÚ__init__zPandasColumn.__init__V   su   € ô
 �fœbŸl™lÔ+Üðð !Ÿ.™.Ð)ð *2ð2óð ô ˜&¤"§)¡)Ô,Ü%Ð(8¼¸f»¸ÐFVÐ&WÓXÐXð ˆŒ	Ø%ˆÕó    c                ó.   — | j                   j                  S )z2
        Size of the column, in elements.
        )r-   Úsize©r/   s    r2   r6   zPandasColumn.sizej   s   € ð �y‰y�~‰~Ðr4   c                 ó   — y)z7
        Offset of first element. Always zero.
        r   © r7   s    r2   ÚoffsetzPandasColumn.offsetp   s   € ð r4   c                óø  — | j                   j                  }t        |t        j                  «      rb| j                   j
                  j                  }| j                  |j                  «      \  }}}}t        j                  ||t        j                  fS t        |«      rMt        | j                   «      dv r+t        j                  dt        |«      t        j                  fS t!        d«      ‚| j                  |«      S )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/   r?   rB   Ú_ÚbitwidthÚc_arrow_dtype_f_strs         r2   r?   zPandasColumn.dtypex   sß   € à—	‘	—‘ˆä�eœR×0Ñ0Ô1Ø—I‘I×$Ñ$×*Ñ*ˆEð ×,Ñ,¨U¯[©[Ó9ñØØØ#Øô ×%Ñ%ØØ#Ü×!Ñ!ð	ð ô ˜UÔ#Ü˜4Ÿ9™9Ó%Ð)<Ñ<ä×$Ñ$ØÜ(¨Ó/Ü×%Ñ%ð	ð ô &Ð&VÓWÐWà×/Ñ/°Ó6Ð6r4   c                óä  — t         j                  |j                  d«      }|€t        d|› d�«      ‚t	        |t
        «      r|j                  j                  }nZt	        |t        «      r|j                  j                  }n3t	        |t        «      r|j                  j                  }n|j                  }|dk(  r||j                  t        j                  |fS ||j                  dz  t        |«      |fS )z/
        See `self.dtype` for details.
        Nú
Data type z& not supported by interchange protocolzbool[pyarrow]r>   )Ú	_NP_KINDSÚgetÚkindÚ
ValueErrorr%   r   Únumpy_dtypeÚ	byteorderr   Úbaser   Úitemsizer   ÚBOOLr   )r/   r?   rN   rQ   s       r2   rC   z$PandasColumn._dtype_from_pandasdtype–   sÔ   € ô �}‰}˜UŸZ™Z¨Ó.ˆØˆ<ä˜z¨%¨Ð0VÐWÓXÐXÜ�eœZÔ(Ø×)Ñ)×3Ñ3‰IÜ˜œÔ/ØŸ
™
×,Ñ,‰IÜ˜œÔ/Ø×)Ñ)×3Ñ3‰IàŸ™ˆIà�OÒ#ð Ø—‘Ü× Ñ Øð	ð ð �U—^‘^ aÑ'Ô)=¸eÓ)DÀiÐOÐOr4   c                ó  — | j                   d   t        j                  k(  st        d«      ‚| j                  j
                  j                  dt        t        j                  | j                  j
                  j                  «      «      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.
        r   zCdescribe_categorical only works on a column with categorical dtype!T)Ú
is_orderedÚis_dictionaryÚ
categories)r?   r   rD   r(   r-   ÚcatÚorderedr"   r&   r*   rX   r7   s    r2   Údescribe_categoricalz!PandasColumn.describe_categorical·   si   € ð$ �z‰z˜!‰}¤	× 5Ñ 5Ò5ÜØUóð ð
 Ÿ)™)Ÿ-™-×/Ñ/Ø!Ü&¤r§y¡y°·±·±×1IÑ1IÓ'JÓKñ
ð 	
r4   c                ó  — t        | j                  j                  t        «      rt        j
                  }d}||fS t        | j                  j                  t        «      rb| j                  j                  j                  j                  d   j                  «       d   €t        j                  d fS t        j                  dfS | j                  d   }	 t        |   \  }}||fS # t        $ r}t        d|› d�«      |‚d }~ww xY w)Né   r   rK   z not yet supported)r%   r-   r?   r   r   ÚUSE_BYTEMASKr   ÚarrayÚ	_pa_arrayÚchunksÚbuffersÚNON_NULLABLEÚUSE_BITMASKÚ_NULL_DESCRIPTIONÚKeyErrorr+   )r/   Úcolumn_null_dtypeÚ
null_valuerN   ÚnullÚvalueÚerrs          r2   Údescribe_nullzPandasColumn.describe_nullÔ   sì   € ä�d—i‘i—o‘o¤Ô7Ü .× ;Ñ ;ÐØˆJØ$ jÐ0Ð0Ü�d—i‘i—o‘o¤zÔ2ð �y‰y�‰×(Ñ(×/Ñ/°Ñ2×:Ñ:Ó<¸QÑ?ÐGÜ%×2Ñ2°DÐ8Ð8Ü!×-Ñ-¨qÐ0Ð0Ø�z‰z˜!‰}ˆð	VÜ+¨DÑ1‰KˆD�%ð �Uˆ{Ðøô ò 	VÜ%¨
°4°&Ð8JÐ&KÓLÐRUÐUûð	Vús   ÃC! Ã!	C?Ã*C:Ã:C?c                óŠ   — | j                   j                  «       j                  «       }t        «       s|j	                  «       }|S )zB
        Number of null elements. Should always be known.
        )r-   ÚisnaÚsumr   Úitem)r/   Úresults     r2   Ú
null_countzPandasColumn.null_countè   s3   € ð
 —‘—‘Ó!×%Ñ%Ó'ˆÜ#Ô%Ø—[‘[“]ˆFØˆr4   c                ó2   — d| j                   j                  iS )z8
        Store specific metadata of the column.
        zpandas.index)r-   Úindexr7   s    r2   ÚmetadatazPandasColumn.metadataò   s   € ð
  §	¡	§¡Ð0Ð0r4   c                 ó   — y)zE
        Return the number of chunks the column consists of.
        r]   r9   r7   s    r2   Ú
num_chunkszPandasColumn.num_chunksù   s   € ð r4   Nc              #  ó   K  — |rt|dkD  rot        | j                  «      }||z  }||z  dk7  r|dz  }t        d||z  |«      D ]4  }t        | j                  j                  |||z    | j
                  «      –— Œ6 y| –— y­w)zy
        Return an iterator yielding the chunks.
        See `DataFrame.get_chunks` for details on ``n_chunks``.
        r]   r   N)Úlenr-   Úranger"   Úilocr.   )r/   Ún_chunksr6   ÚstepÚstarts        r2   Ú
get_chunkszPandasColumn.get_chunksÿ   s‹   è ø€ ñ
 ˜ 1šÜ�t—y‘y“>ˆDØ˜8Ñ#ˆDØ�h‰ !Ò#Ø˜‘	�Ü˜q $¨¡/°4Ó8ò �Ü"Ø—I‘I—N‘N 5¨5°4©<Ð8¸$×:JÑ:Jóó ñð
 ‹Jùs   ‚A<A>c                ó¼   — | j                  «       dddœ}	 | j                  «       |d<   	 | j                  «       |d<   |S # t        $ r Y Œ!w xY w# t        $ r Y |S w xY w)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/   rb   s     r2   Úget_bufferszPandasColumn.get_buffers  s€   € ð( ×)Ñ)Ó+ØØñ"
ˆð	Ø"&×";Ñ";Ó"=ˆG�JÑð	Ø!%×!9Ñ!9Ó!;ˆG�IÑð ˆøô ò 	Ùð	ûô
 ò 	Øàˆð	ús    –? ªA ¿	AÁ
AÁ	AÁAc                óÜ  — | j                   d   t        j                  k(  r´t        | j                   d   «      dkD  r4| j                  j
                  j                  d«      j                  «       }n| j                  j                  «       }t        || j                  ¬«      }t        j                  dt        j                  t        j                  f}||fS | j                   d   t        j                  t        j                  t        j                   t        j"                  fv râ| j                   }| j                  j$                  }t'        | j                  j                   t(        «      rD|j*                  j,                  d   }t/        |j1                  «       d   t        |«      ¬«      }||fS t'        | j                  j                   t2        «      r|j4                  }n|j6                  }t        || j                  ¬«      }||fS | j                   d   t        j8                  k(  rV| j                  j:                  j<                  }t        || j                  ¬«      }| j?                  |j                   «      }||fS | j                   d   t        j@                  k(  r±| j                  j                  «       }tC        «       }|D ]4  }t'        |tD        «      sŒ|jG                  |jI                  d	¬
«      «       Œ6 t        tK        jL                  |d¬«      «      }t        j                  dt        jN                  t        j                  f}||fS tQ        d| j                  j                   › d�«      ‚)zZ
        Return the buffer containing the data and the buffer's associated dtype.
        r   é   é   N)r1   é@   r]   ©Úlengthúutf-8©ÚencodingÚuint8)r?   r>   rK   r$   ))r?   r   ÚDATETIMEry   r-   ÚdtÚ
tz_convertÚto_numpyr   r.   ÚINTr   ÚINT64r   rE   ÚUINTÚFLOATrT   r_   r%   r   r`   ra   r   rb   r   Ú_dataÚ_ndarrayrD   rA   Ú_codesrC   rF   Ú	bytearrayÚstrÚextendÚencodeÚnpÚ
frombufferÚUINT8r+   )	r/   Únp_arrÚbufferr?   ÚarrrB   Úbufr   Úobjs	            r2   r„   zPandasColumn._get_data_buffer5  s±  € ð �:‰:�a‰=œI×.Ñ.Ò.ô �4—:‘:˜a‘=Ó! AÒ%ØŸ™Ÿ™×0Ñ0°Ó6×?Ñ?ÓA‘àŸ™×+Ñ+Ó-�Ü! &°T×5EÑ5EÔFˆFä—‘ØÜ×!Ñ!Ü×!Ñ!ð	ˆEðt �uˆ}Ðði �Z‰Z˜‰]Ü�M‰MÜ�N‰NÜ�O‰OÜ�N‰Nð	
ñ 
ð —J‘JˆEØ—)‘)—/‘/ˆCÜ˜$Ÿ)™)Ÿ/™/¬:Ô6ð —m‘m×*Ñ*¨1Ñ-�Ü,Ø—K‘K“M !Ñ$Ü˜s›8ô�ð ˜u�}Ð$Ü˜$Ÿ)™)Ÿ/™/¬?Ô;ØŸ™‘àŸ™�Ü! &°T×5EÑ5EÔFˆFð> �uˆ}Ðð= �Z‰Z˜‰]œi×3Ñ3Ò3Ø—I‘I×$Ñ$×+Ñ+ˆEÜ! %°D×4DÑ4DÔEˆFØ×0Ñ0°·±Ó=ˆEð6 �uˆ}Ðð5 �Z‰Z˜‰]œi×.Ñ.Ò.à—)‘)×$Ñ$Ó&ˆCÜ“ˆAð ò ;�Ü˜c¤3Õ'Ø—H‘H˜SŸZ™Z°˜ZÓ9Õ:ð;ô "¤"§-¡-°¸Ô"AÓBˆFô —‘ØÜ×!Ñ!Ü×!Ñ!ð	ˆEð �uˆ}Ðô &¨
°4·9±9·?±?Ð2CÐCSÐ&TÓUÐUr4   c                óÄ  — | j                   \  }}t        | j                  j                  t        «      rœ| j                  j
                  j                  j                  d   }t        j                  dt        j                  t        j                  f}|j                  «       d   €yt        |j                  «       d   t        |«      ¬«      }||fS t        | j                  j                  t         «      r_| j                  j
                  j"                  }t%        |«      }t        j                  dt        j                  t        j                  f}||fS | j                  d   t        j&                  k(  rº| j                  j)                  «       }|dk(  }| }t+        j,                  t        |«      ft*        j.                  ¬«      }t1        |«      D ]  \  }	}
t        |
t2        «      r|n|||	<   Œ t%        |«      }t        j                  dt        j                  t        j                  f}||fS 	 t4        |   › d�}t;        |«      ‚# t6        $ r}t9        d«      |‚d}~ww xY w)	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   r]   NrŒ   r>   ©Úshaper?   z! so does not have a separate maskzSee self.describe_null)rl   r%   r-   r?   r   r_   r`   ra   r   rT   r   r   rE   rb   r   ry   r   Ú_maskr   rF   r•   r¡   ÚzerosÚbool_Ú	enumeraterž   Ú_NO_VALIDITY_BUFFERrf   r+   r	   )r/   ri   Úinvalidr¦   r?   r¥   Úmaskr§   Úvalidr   r¨   Úmsgrk   s                r2   r…   z!PandasColumn._get_validity_buffer€  sú  € ð ×*Ñ*‰ˆˆgä�d—i‘i—o‘o¤zÔ2ð —)‘)—/‘/×+Ñ+×2Ñ2°1Ñ5ˆCÜ—^‘^ Q¬×(8Ñ(8¼*×:KÑ:KÐLˆEØ�{‰{‹}˜QÑÐ'ØÜ(Ø—‘“˜aÑ Ü˜3“xôˆFð ˜5�=Ð ä�d—i‘i—o‘o¤Ô7Ø—9‘9—?‘?×(Ñ(ˆDÜ! $Ó'ˆFÜ—^‘^ Q¬×(8Ñ(8¼*×:KÑ:KÐLˆEØ˜5�=Ð à�:‰:�a‰=œI×,Ñ,Ò,ð —)‘)×$Ñ$Ó&ˆCð ˜q‘LˆEØ�iˆGä—8‘8¤3 s£8 +´R·X±XÔ>ˆDÜ# C›.ò E‘��3Ü#-¨c´3Ô#7™%¸W��Q’ðEô
 " $Ó'ˆFô —^‘^ Q¬×(8Ñ(8¼*×:KÑ:KÐLˆEà˜5�=Ð ð	IÜ(¨Ñ.Ð/Ð/PÐQˆCô
 ˜cÓ"Ð"øô	 ò 	Iä%Ð&>Ó?ÀSÐHûð	Iús   È.I É	IÉIÉIc                ó  — | j                   d   t        j                  k(  rØ| j                  j	                  «       }d}t        j                  t        |«      dz   ft
        j                  ¬«      }t        |«      D ]=  \  }}t        |t        «      r |j                  d¬«      }|t        |«      z  }|||dz   <   Œ? t        |«      }t        j                  dt        j                   t"        j$                  f}||fS t'        d«      ‚)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.
        r   r]   rª   rŽ   r�   r‹   zJThis column has a fixed-length dtype so it does not have an offsets buffer)r?   r   rF   r-   r•   r¡   r­   ry   Úint64r¯   r%   rž   r    r   r–   r   r—   r   rE   r	   )	r/   rA   Úptrrƒ   r   Úvr   r¥   r?   s	            r2   r†   z PandasColumn._get_offsets_buffer¹  sï   € ð �:‰:�a‰=œI×,Ñ,Ò,à—Y‘Y×'Ñ'Ó)ˆFØˆCÜ—h‘h¤c¨&£k°A¡oÐ%7¼r¿x¹xÔHˆGÜ! &Ó)ò %‘��1ô ˜a¤Ô%ØŸ™¨'˜Ó2�AØœ3˜q›6‘M�Cà!$�˜˜A™’ð%ô " 'Ó*ˆFô —‘ØÜ×!Ñ!Ü×!Ñ!ð	ˆEð �uˆ}Ðô "ð5óð r4   )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__Ú__doc__r3   r6   Úpropertyr:   r
   r?   rC   r[   rl   rr   ru   rw   r   r‡   r„   r…   r†   r9   r4   r2   r"   r"   J   s»   „ ñ	ô&ó(ð òó ðð ò7ó ð7ó:PðB ñ
ó ð
ð8 ñó ðð& òó ðð ò1ó ð1óôó"#ðJIà	7óIóV7#ôr&r4   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™   rT   rF   r’   rL   ÚUSE_NANÚUSE_SENTINELrc   rD   r^   re   r°   r"   r9   r4   r2   ú<module>rÒ      sl  ðÝ "÷ó
 å /å (Ý $Ý )Ý 2å 5ã ÷õ -÷÷ó ÷ñ ñ ÝAð 
�‰Ø	�‰Ø	�‰Ø	�‰Ø	×	Ñ	Ø	×	Ñ	Ø	×	Ñ	ñ€	ð ‡O�O�n×,Ñ,¨dÐ3Ø×Ñ˜×4Ñ4°dÐ;Ø‡M�M�N×/Ñ/°Ð6Ø‡N�N�^×0Ñ0°$Ð7Ø‡N�N�^×0Ñ0°$Ð7ð ×Ñ˜N×7Ñ7¸Ð<à×Ñ�~×2Ñ2°AÐ6ðÐ ð ×ÑÐ!>Ø×ÑÐ:Ø×ÑÐ!DðÐ ôU�6õ Ur4   