o
    i!                     @  sn  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r?d dlmZmZ d dlmZ d dlmZ d dlmZ G d	d
 d
eZG dd deZeeeeef Zded< G dd deZG dd de
ZG dd de
ZG dd de	ZG dd de	Z G dd de	Z!G dd de	Z"G dd dZ#G dd  d e$Z%G d!d" d"Z&e&'d e&_(e&'d#e&_)d$S )%    )annotations)IntEnum)TYPE_CHECKINGAnyClassVarLiteralProtocol	TypedDict)issue_unstable_warning)IterableSequence)	TypeAlias)PolarsBuffer)PolarsColumnc                   @  s0   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.                  	   
   N)__name__
__module____qualname____doc__ZCPUCUDAZ
CPU_PINNEDZOPENCLZVULKANZMETALZVPIZROCM r   r   R/home/app/Keep/.python/lib/python3.10/site-packages/polars/interchange/protocol.pyr      s    r   c                   @  s,   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   INTZUINTFLOATZBOOLSTRINGZDATETIMEZCATEGORICALr   r   r   r   r    $   s    r    r   Dtypec                   @  s$   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   ZNON_NULLABLEZUSE_NANZUSE_SENTINELZUSE_BITMASKZUSE_BYTEMASKr   r   r   r   r)   F   s    r)   c                   @  s*   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] | NoneZvalidityoffsetsNr   r   r   r   __annotations__r   r   r   r   r*   _   s
   
 r*   c                   @  s*   e Zd ZU dZded< ded< ded< dS )	CategoricalDescriptionz$Description of a categorical column.boolZ
is_orderedzLiteral[True]Zis_dictionaryr   
categoriesNr-   r   r   r   r   r/   r   s
   
 r/   c                   @  s@   e Zd ZdZedddZedddZdd	d
ZdddZdS )BufferzInterchange buffer object.returnintc                 C     dS )zBuffer size in bytes.Nr   selfr   r   r   bufsize       zBuffer.bufsizec                 C  r5   )z-Pointer to start of the buffer as an integer.Nr   r6   r   r   r   ptr   r9   z
Buffer.ptrr   c                 C  r5   )z-Represent this structure as DLPack interface.Nr   r6   r   r   r   
__dlpack__   r9   zBuffer.__dlpack__#tuple[DlpackDeviceType, int | None]c                 C  r5   )zCDevice type and device ID for where the data in the buffer resides.Nr   r6   r   r   r   __dlpack_device__   r9   zBuffer.__dlpack_device__Nr3   r4   )r3   r   )r3   r<   )	r   r   r   r   propertyr8   r:   r;   r=   r   r   r   r   r2   ~   s    
r2   c                   @  s   e Zd ZdZd!ddZed!ddZed"d	d
Zed#ddZed$ddZ	ed%ddZ
ed&ddZd!ddZd'd(ddZd)dd ZdS )*ColumnzInterchange column object.r3   r4   c                 C  r5   )zSize of the column in elements.Nr   r6   r   r   r   size   r9   zColumn.sizec                 C  r5   )zOOffset of the first element with respect to the start of the underlying buffer.Nr   r6   r   r   r   offset   r9   zColumn.offsetr(   c                 C  r5   )zData type of the column.Nr   r6   r   r   r   dtype   r9   zColumn.dtyper/   c                 C  r5   )z7Description of the categorical data type of the column.Nr   r6   r   r   r   describe_categorical   r9   zColumn.describe_categoricaltuple[ColumnNullType, Any]c                 C  r5   )z7Description of the null representation the column uses.Nr   r6   r   r   r   describe_null   r9   zColumn.describe_null
int | Nonec                 C  r5   )z"Number of null elements, if known.Nr   r6   r   r   r   
null_count   r9   zColumn.null_countdict[str, Any]c                 C  r5   )zThe metadata for the column.Nr   r6   r   r   r   metadata   r9   zColumn.metadatac                 C  r5   )z3Return the number of chunks the column consists of.Nr   r6   r   r   r   
num_chunks   r9   zColumn.num_chunksNn_chunksIterable[Column]c                 C  r5   )z.Return an iterator yielding the column chunks.Nr   r7   rL   r   r   r   
get_chunks   r9   zColumn.get_chunksr*   c                 C  r5   )z6Return a dictionary containing the underlying buffers.Nr   r6   r   r   r   get_buffers   r9   zColumn.get_buffersr>   )r3   r(   )r3   r/   )r3   rE   r3   rG   r3   rI   N)rL   rG   r3   rM   )r3   r*   )r   r   r   r   rA   r?   rB   rC   rD   rF   rH   rJ   rK   rO   rP   r   r   r   r   r@      s$    

r@   c                   @  s   e Zd ZU dZded< 		d2d3d
dZed4ddZd5ddZd6ddZ	d5ddZ
d7ddZd8ddZd9d d!Zd:d#d$Zd;d'd(Zd<d+d,Zd=d>d0d1Zd-S )?	DataFramezInterchange dataframe object.zClassVar[int]versionFTnan_as_nullr0   
allow_copyr3   c                 C  r5   zNConvert to a dataframe object implementing the dataframe interchange protocol.Nr   r7   rV   rW   r   r   r   __dataframe__   r9   zDataFrame.__dataframe__rI   c                 C  r5   )zThe metadata for the dataframe.Nr   r6   r   r   r   rJ      r9   zDataFrame.metadatar4   c                 C  r5   )z.Return the number of columns in the dataframe.Nr   r6   r   r   r   num_columns   r9   zDataFrame.num_columnsrG   c                 C  r5   )z9Return the number of rows in the dataframe, if available.Nr   r6   r   r   r   num_rows   r9   zDataFrame.num_rowsc                 C  r5   )z7Return the number of chunks the dataframe consists of..Nr   r6   r   r   r   rK      r9   zDataFrame.num_chunksIterable[str]c                 C  r5   )zReturn the column names.Nr   r6   r   r   r   column_names   r9   zDataFrame.column_namesir@   c                 C  r5   )z,Return the column at the indicated position.Nr   )r7   r_   r   r   r   
get_column   r9   zDataFrame.get_columnnamestrc                 C  r5   )z&Return the column with the given name.Nr   )r7   ra   r   r   r   get_column_by_name   r9   zDataFrame.get_column_by_namerM   c                 C  r5   )z(Return an iterator yielding the columns.Nr   r6   r   r   r   get_columns   r9   zDataFrame.get_columnsindicesSequence[int]c                 C  r5   )zACreate a new dataframe by selecting a subset of columns by index.Nr   )r7   re   r   r   r   select_columns   r9   zDataFrame.select_columnsnamesSequence[str]c                 C  r5   )z@Create a new dataframe by selecting a subset of columns by name.Nr   )r7   rh   r   r   r   select_columns_by_name   r9   z DataFrame.select_columns_by_nameNrL   Iterable[DataFrame]c                 C  r5   )z8Return an iterator yielding the chunks of the dataframe.Nr   rN   r   r   r   rO      r9   zDataFrame.get_chunksFT)rV   r0   rW   r0   r3   rT   rR   r>   rQ   )r3   r]   )r_   r4   r3   r@   )ra   rb   r3   r@   )r3   rM   )re   rf   r3   rT   )rh   ri   r3   rT   rS   )rL   rG   r3   rk   )r   r   r   r   r.   rZ   r?   rJ   r[   r\   rK   r^   r`   rc   rd   rg   rj   rO   r   r   r   r   rT      s$   
 








rT   c                   @  s    e Zd ZdZ		dddd	Zd
S )SupportsInterchangezHDataframe that supports conversion into an interchange dataframe object.FTrV   r0   rW   r3   c                 C  r5   rX   r   rY   r   r   r   rZ      r9   z!SupportsInterchange.__dataframe__Nrl   )rV   r0   rW   r0   r3   rm   )r   r   r   r   rZ   r   r   r   r   rm      s
    rm   c                   @  s    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   ZLITTLEZBIGZNATIVEZNAr   r   r   r   rn      s    rn   c                   @  s   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   rs      s    rs   c                   @  sf   e Zd ZU dZded< dddZedd	d
ZedddZedddZ	edddZ
dddZdS )CompatLevelz#Data structure compatibility level.r4   _versionr3   Nonec                 C  s   d}t |)Nz0it is not allowed to create a CompatLevel object)	TypeError)r7   msgr   r   r   __init__  s   zCompatLevel.__init__rU   c                 C  s   t t }| |_|S rS   )rt   __new__ru   )rU   Zcompat_levelr   r   r   _with_version  s   
zCompatLevel._with_versionc                   C     t jS rS   )rt   _future1r   r   r   r   _newest  s   zCompatLevel._newestc                   C  s   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
   rt   r~   r   r   r   r   newest  s   	zCompatLevel.newestc                   C  r|   )zGet the most compatible level.)rt   _compatibler   r   r   r   oldest   s   zCompatLevel.oldestrb   c                 C  s"   d| j j d| j j d| j dS )Nro   .z: rp   )	__class__r   r   ru   r6   r   r   r   __repr__%  s   "zCompatLevel.__repr__N)r3   rv   )rU   r4   r3   rt   )r3   rt   )r3   rb   )r   r   r   r   r.   ry   staticmethodr{   r~   r   r   r   r   r   r   r   rt      s   
 
rt   r   N)*
__future__r   enumr   typingr   r   r   r   r   r	   Zpolars._utils.unstabler
   collections.abcr   r   r   Zpolars.interchange.bufferr   Zpolars.interchange.columnr   r   r    tupler4   rb   r(   r.   r)   r*   r/   r2   r@   rT   rm   rn   RuntimeErrorrs   rt   r{   r   r}   r   r   r   r   <module>   s0     	(/	*