
    q-Ph"                       U d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ er0d dlZd dlmZmZ d dlmZ d dlmZ ej        d	k    rd d
lmZ nd d
lmZ  G d de          Z G d de          Zeeeeef         Zded<    G d de          Z G d de
          Z  G d de
          Z! G d de	          Z" G d de	          Z# G d de	          Z$ G d de	          Z% G d d           Z& G d! d"e'          Z( G d# d$          Z)e)*                    d           e)_+        e)*                    d%          e)_,        dS )&    )annotations)IntEnum)TYPE_CHECKINGAnyClassVarLiteralProtocol	TypedDict)issue_unstable_warningN)IterableSequence)PolarsBuffer)PolarsColumn)   
   )	TypeAliasc                  2    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
S )DlpackDeviceTypez3Integer enum for device type codes matching DLPack.      r            	   r   N)__name__
__module____qualname____doc__CPUCUDA
CPU_PINNEDOPENCLVULKANMETALVPIROCM     [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/interchange/protocol.pyr   r      s<        ==
CDJFFE
CDDDr(   r   c                  .    e Zd ZdZdZdZdZdZdZdZ	dZ
d	S )
	DtypeKinda  
    Integer enum for data types.

    Attributes
    ----------
    INT : int
        Matches to signed integer data type.
    UINT : int
        Matches to unsigned integer data type.
    FLOAT : int
        Matches to floating point data type.
    BOOL : int
        Matches to boolean data type.
    STRING : int
        Matches to string data type (UTF-8 encoded).
    DATETIME : int
        Matches to datetime data type.
    CATEGORICAL : int
        Matches to categorical data type.
    r   r   r               N)r   r   r   r   INTUINTFLOATBOOLSTRINGDATETIMECATEGORICALr'   r(   r)   r+   r+   )   s=         * CDEDFHKKKr(   r+   r   Dtypec                  &    e Zd ZdZdZdZdZdZdZdS )ColumnNullTypea  
    Integer enum for null type representation.

    Attributes
    ----------
    NON_NULLABLE : int
        Non-nullable column.
    USE_NAN : int
        Use explicit float NaN value.
    USE_SENTINEL : int
        Sentinel value besides NaN.
    USE_BITMASK : int
        The bit is set/unset representing a null on a certain position.
    USE_BYTEMASK : int
        The byte is set/unset representing a null on a certain position.
    r   r   r   r   r   N)	r   r   r   r   NON_NULLABLEUSE_NANUSE_SENTINELUSE_BITMASKUSE_BYTEMASKr'   r(   r)   r9   r9   K   s3         " LGLKLLLr(   r9   c                  2    e Zd ZU dZded<   ded<   ded<   dS )ColumnBufferszBuffers backing a column.ztuple[PolarsBuffer, Dtype]dataz!tuple[PolarsBuffer, Dtype] | NonevalidityoffsetsNr   r   r   r   __annotations__r'   r(   r)   r@   r@   d   sB         ## %$$$
 0/// /.....r(   r@   c                  2    e Zd ZU dZded<   ded<   ded<   dS )	CategoricalDescriptionz$Description of a categorical column.bool
is_orderedzLiteral[True]is_dictionaryr   
categoriesNrD   r'   r(   r)   rG   rG   w   s@         ..      r(   rG   c                  R    e Zd ZdZedd            Zedd            ZddZdd	Zd
S )BufferzInterchange buffer object.returnintc                    dS )zBuffer size in bytes.Nr'   selfs    r)   bufsizezBuffer.bufsize         r(   c                    dS )z-Pointer to start of the buffer as an integer.Nr'   rQ   s    r)   ptrz
Buffer.ptr   rT   r(   r   c                    dS )z-Represent this structure as DLPack interface.Nr'   rQ   s    r)   
__dlpack__zBuffer.__dlpack__   rT   r(   #tuple[DlpackDeviceType, int | None]c                    dS )zCDevice type and device ID for where the data in the buffer resides.Nr'   rQ   s    r)   __dlpack_device__zBuffer.__dlpack_device__   rT   r(   NrN   rO   )rN   r   )rN   rY   )	r   r   r   r   propertyrS   rV   rX   r[   r'   r(   r)   rM   rM      s        $$$ $ $ X$ < < < X<< < < <R R R R R Rr(   rM   c                      e Zd ZdZddZedd            Zedd            Zedd	            Zedd            Z	edd            Z
edd            ZddZdddZddZdS ) ColumnzInterchange column object.rN   rO   c                    dS )zSize of the column in elements.Nr'   rQ   s    r)   sizezColumn.size   rT   r(   c                    dS )zOOffset of the first element with respect to the start of the underlying buffer.Nr'   rQ   s    r)   offsetzColumn.offset   rT   r(   r7   c                    dS )zData type of the column.Nr'   rQ   s    r)   dtypezColumn.dtype   rT   r(   rG   c                    dS )z7Description of the categorical data type of the column.Nr'   rQ   s    r)   describe_categoricalzColumn.describe_categorical   rT   r(   tuple[ColumnNullType, Any]c                    dS )z7Description of the null representation the column uses.Nr'   rQ   s    r)   describe_nullzColumn.describe_null   rT   r(   
int | Nonec                    dS )z"Number of null elements, if known.Nr'   rQ   s    r)   
null_countzColumn.null_count   rT   r(   dict[str, Any]c                    dS )zThe metadata for the column.Nr'   rQ   s    r)   metadatazColumn.metadata   rT   r(   c                    dS )z3Return the number of chunks the column consists of.Nr'   rQ   s    r)   
num_chunkszColumn.num_chunks   rT   r(   Nn_chunksIterable[Column]c                    dS )z.Return an iterator yielding the column chunks.Nr'   rR   rs   s     r)   
get_chunkszColumn.get_chunks   rT   r(   r@   c                    dS )z6Return a dictionary containing the underlying buffers.Nr'   rQ   s    r)   get_bufferszColumn.get_buffers   rT   r(   r\   )rN   r7   )rN   rG   )rN   rh   rN   rk   rN   rn   N)rs   rk   rN   rt   )rN   r@   )r   r   r   r   ra   r]   rc   re   rg   rj   rm   rp   rr   rw   ry   r'   r(   r)   r_   r_      sE       $$. . . . ^ ^ ^ X^ ' ' ' X' F F F XF F F F XF 1 1 1 X1 + + + X+B B B B= = = = =E E E E E Er(   r_   c                      e Zd ZU dZded<   	 	 d&d'd
Zed(d            Zd)dZd*dZ	d)dZ
d+dZd,dZd-dZd.dZd/dZd0d!Zd1d2d%Zd"S )3	DataFramezInterchange dataframe object.zClassVar[int]versionFTnan_as_nullrH   
allow_copyrN   c                    dS zNConvert to a dataframe object implementing the dataframe interchange protocol.Nr'   rR   r   r   s      r)   __dataframe__zDataFrame.__dataframe__   rT   r(   rn   c                    dS )zThe metadata for the dataframe.Nr'   rQ   s    r)   rp   zDataFrame.metadata   rT   r(   rO   c                    dS )z.Return the number of columns in the dataframe.Nr'   rQ   s    r)   num_columnszDataFrame.num_columns   rT   r(   rk   c                    dS )z9Return the number of rows in the dataframe, if available.Nr'   rQ   s    r)   num_rowszDataFrame.num_rows   rT   r(   c                    dS )z7Return the number of chunks the dataframe consists of..Nr'   rQ   s    r)   rr   zDataFrame.num_chunks   rT   r(   Iterable[str]c                    dS )zReturn the column names.Nr'   rQ   s    r)   column_nameszDataFrame.column_names   rT   r(   ir_   c                    dS )z,Return the column at the indicated position.Nr'   )rR   r   s     r)   
get_columnzDataFrame.get_column   rT   r(   namestrc                    dS )z&Return the column with the given name.Nr'   )rR   r   s     r)   get_column_by_namezDataFrame.get_column_by_name   rT   r(   rt   c                    dS )z(Return an iterator yielding the columns.Nr'   rQ   s    r)   get_columnszDataFrame.get_columns   rT   r(   indicesSequence[int]c                    dS )zACreate a new dataframe by selecting a subset of columns by index.Nr'   )rR   r   s     r)   select_columnszDataFrame.select_columns   rT   r(   namesSequence[str]c                    dS )z@Create a new dataframe by selecting a subset of columns by name.Nr'   )rR   r   s     r)   select_columns_by_namez DataFrame.select_columns_by_name   rT   r(   Nrs   Iterable[DataFrame]c                    dS )z8Return an iterator yielding the chunks of the dataframe.Nr'   rv   s     r)   rw   zDataFrame.get_chunks   rT   r(   FT)r   rH   r   rH   rN   r~   r{   r\   rz   )rN   r   )r   rO   rN   r_   )r   r   rN   r_   )rN   rt   )r   r   rN   r~   )r   r   rN   r~   r|   )rs   rk   rN   r   )r   r   r   r   rE   r   r]   rp   r   r   rr   r   r   r   r   r   r   rw   r'   r(   r)   r~   r~      sR        '' "] ] ] ] ] . . . X.= = = =H H H HF F F F' ' ' '; ; ; ;5 5 5 57 7 7 7P P P PO O O OG G G G G G Gr(   r~   c                       e Zd ZdZ	 	 d
ddZd	S )SupportsInterchangezHDataframe that supports conversion into an interchange dataframe object.FTr   rH   r   rN   c                    dS r   r'   r   s      r)   r   z!SupportsInterchange.__dataframe__   rT   r(   Nr   )r   rH   r   rH   rN   r   )r   r   r   r   r   r'   r(   r)   r   r      sB        RR "] ] ] ] ] ] ]r(   r   c                  "    e Zd ZdZdZdZdZdZdS )
Endiannessz.Enum indicating the byte-order of a data type.<>=|N)r   r   r   r   LITTLEBIGNATIVENAr'   r(   r)   r   r      s(        88F
CF	BBBr(   r   c                      e Zd ZdZdS )CopyNotAllowedErrorzMException raised when a copy is required, but `allow_copy` is set to `False`.N)r   r   r   r   r'   r(   r)   r   r      s        WWWWr(   r   c                      e Zd ZdZddZedd            Zedd            Zedd	            Zedd
            Z	ddZ
dS )CompatLevelz#Data structure compatibility level.rN   Nonec                $    d}t          |          )Nz0it is not allowed to create a CompatLevel object)	TypeError)rR   msgs     r)   __init__zCompatLevel.__init__  s    @nnr(   r   rO   c                R    t                               t                     }| |_        |S r|   )r   __new___version)r   compat_levels     r)   _with_versionzCompatLevel._with_version  s#    "**;77 'r(   c                     t           j        S r|   )r   _future1r'   r(   r)   _newestzCompatLevel._newest  s    ##r(   c                 R    t          d           t                                          S )z
        Get the highest supported compatibility level.

        .. warning::
            Highest compatibility level is considered **unstable**. It may be changed
            at any point without it being considered a breaking change.
        z=using the highest compatibility level is considered unstable.)r   r   r   r'   r(   r)   newestzCompatLevel.newest  s-     	K	
 	
 	
 ""$$$r(   c                     t           j        S )zGet the most compatible level.)r   _compatibler'   r(   r)   oldestzCompatLevel.oldest#  s     &&r(   r   c                L    d| j         j         d| j         j         d| j         dS )Nr   .z: r   )	__class__r   r   r   rQ   s    r)   __repr__zCompatLevel.__repr__(  s/    ^4>,^^t~/J^^dm^^^^r(   N)rN   r   )r   rO   rN   r   )rN   r   )rN   r   )r   r   r   r   r   staticmethodr   r   r   r   r   r'   r(   r)   r   r     s        --       \
 $ $ $ \$ % % % \% ' ' ' \'_ _ _ _ _ _r(   r   r   )-
__future__r   enumr   typingr   r   r   r   r	   r
   polars._utils.unstabler   syscollections.abcr   r   polars.interchange.bufferr   polars.interchange.columnr   version_infor   typing_extensionsr   r+   tuplerO   r   r7   rE   r9   r@   rG   rM   r_   r~   r   r   RuntimeErrorr   r   r   r   r   r'   r(   r)   <module>r      s   " " " " " " "                      : 9 9 9 9 9 
0JJJ22222222666666666666
7""$$$$$$$//////
 
 
 
 
w 
 
 
       > Cc12 2 2 2 2    W   2/ / / / /I / / /&	 	 	 	 	Y 	 	 	R R R R RX R R R$%E %E %E %E %EX %E %E %EP,G ,G ,G ,G ,G ,G ,G ,G^] ] ] ] ]( ] ] ]       X X X X X, X X X%_ %_ %_ %_ %_ %_ %_ %_P &33A66 "0033   r(   