
    q-Ph                    z    d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
 erd dlmZ d dlmZ  G d de          Zd	S )
    )annotations)TYPE_CHECKING)BufferCopyNotAllowedErrorDlpackDeviceType	DtypeKind)polars_dtype_to_dtype)NoReturn)Seriesc                  h    e Zd ZdZdddd
Zedd            Zedd            ZddZddZ	ddZ
dS )PolarsBufferaQ  
    A buffer object backed by a Polars Series consisting of a single chunk.

    Parameters
    ----------
    data
        The Polars Series backing the buffer object.
    allow_copy
        Allow data to be copied during operations on this column. If set to `False`,
        a RuntimeError will be raised if data would be copied.
    T)
allow_copydatar   r   boolreturnNonec                   |                                 dk    r'|sd}t          |          |                                }|| _        d S )N   z-non-contiguous buffer must be made contiguous)n_chunksr   rechunk_data)selfr   r   msgs       Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/polars/interchange/buffer.py__init__zPolarsBuffer.__init__    sH    ==??Q /E)#...<<>>D


    intc                .   t          | j        j                  }|d         t          j        k    rB| j                                        \  }}}||z   }t          |d          \  }}|dk    r|S |dz   S | j                                        |d         dz  z  S )zBuffer size in bytes.r      r   )r	   r   dtyper   BOOL_get_buffer_infodivmodlen)r   r    _offsetlengthn_bitsn_bytesrests           r   bufsizezPolarsBuffer.bufsize)   s     &dj&6778y~%% $
 ; ; = =Avvf_F"61--MGTqyy{"z~~58q=11r   c                @    | j                                         \  }}}|S )z-Pointer to start of the buffer as an integer.)r   r"   )r   pointerr%   s      r   ptrzPolarsBuffer.ptr:   s"     
3355Ar   r
   c                $    d}t          |          )z-Represent this structure as DLPack interface.
__dlpack__)NotImplementedError)r   r   s     r   r0   zPolarsBuffer.__dlpack__@   s    !#&&&r   tuple[DlpackDeviceType, None]c                    t           j        dfS )zCDevice type and device ID for where the data in the buffer resides.N)r   CPU)r   s    r   __dlpack_device__zPolarsBuffer.__dlpack_device__E   s     $d++r   strc                t    | j         }| j        }|                                 d         j        }d| d| d|dS )Nr   zPolarsBuffer(bufsize=z, ptr=z	, device=))r+   r.   r5   name)r   r+   r.   devices       r   __repr__zPolarsBuffer.__repr__I   sJ    ,h''))!,1OwOOcOOFOOOOr   N)r   r   r   r   r   r   )r   r   )r   r
   )r   r2   )r   r6   )__name__
__module____qualname____doc__r   propertyr+   r.   r0   r5   r;    r   r   r   r      s        
 
 <@       2 2 2 X2     X
' ' ' '
, , , ,P P P P P Pr   r   N)
__future__r   typingr   polars.interchange.protocolr   r   r   r   polars.interchange.utilsr	   r
   polarsr   r   rA   r   r   <module>rG      s    " " " " " "                        ; : : : : : :P :P :P :P :P6 :P :P :P :P :Pr   