a
    Oªf}  ã                   @  sd   d dl mZ d dlmZmZ d dlmZmZ er@d dlZ	d dl
ZG dd„ deƒZG dd„ deƒZdS )	é    )Úannotations)ÚTYPE_CHECKINGÚAny)ÚBufferÚDlpackDeviceTypeNc                   @  sr   e Zd ZdZdddddœdd„Zed	d
œdd„ƒZed	d
œdd„ƒZdd
œdd„Zdd
œdd„Z	dd
œdd„Z
dS )ÚPandasBufferúF
    Data in the buffer is guaranteed to be contiguous in memory.
    Tz
np.ndarrayÚboolÚNone)ÚxÚ
allow_copyÚreturnc                 C  s:   |j d r0|j |jjfks0|r(| ¡ }ntdƒ‚|| _dS )zG
        Handle only regular columns (= numpy arrays) for now.
        r   zBExports cannot be zero-copy in the case of a non-contiguous bufferN)ÚstridesÚdtypeÚitemsizeÚcopyÚRuntimeErrorÚ_x)Úselfr   r   © r   úW/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/core/interchange/buffer.pyÚ__init__   s    
ÿzPandasBuffer.__init__Úint©r   c                 C  s   | j j| j jj S ©z'
        Buffer size in bytes.
        )r   Úsizer   r   ©r   r   r   r   Úbufsize*   s    zPandasBuffer.bufsizec                 C  s   | j jd d S )ú?
        Pointer to start of the buffer as an integer.
        Údatar   )r   Z__array_interface__r   r   r   r   Úptr1   s    zPandasBuffer.ptrr   c                 C  s
   | j  ¡ S )ú?
        Represent this structure as DLPack interface.
        )r   Ú
__dlpack__r   r   r   r   r"   8   s    zPandasBuffer.__dlpack__ú#tuple[DlpackDeviceType, int | None]c                 C  s
   t jdfS ©zU
        Device type and device ID for where the data in the buffer resides.
        N©r   ÚCPUr   r   r   r   Ú__dlpack_device__>   s    zPandasBuffer.__dlpack_device__Ústrc                 C  s&   dt | j| j|  ¡ d jdœƒ d S )NzPandasBuffer(r   ©r   r    Zdeviceú))r(   r   r    r'   Únamer   r   r   r   Ú__repr__D   s    ýÿÿøÿzPandasBuffer.__repr__N)T©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r    r"   r'   r,   r   r   r   r   r      s   r   c                   @  sp   e Zd ZdZddddœdd„Zeddœd	d
„ƒZeddœdd„ƒZddœdd„Zddœdd„Z	ddœdd„Z
dS )ÚPandasBufferPyarrowr   z	pa.Bufferr   r
   )ÚbufferÚlengthr   c                C  s   || _ || _dS )z0
        Handle pyarrow chunked arrays.
        N)Ú_bufferÚ_length)r   r4   r5   r   r   r   r   W   s    	zPandasBufferPyarrow.__init__r   c                 C  s   | j jS r   )r6   r   r   r   r   r   r   c   s    zPandasBufferPyarrow.bufsizec                 C  s   | j jS )r   )r6   Úaddressr   r   r   r   r    j   s    zPandasBufferPyarrow.ptrr   c                 C  s
   t ƒ ‚dS )r!   N)ÚNotImplementedErrorr   r   r   r   r"   q   s    zPandasBufferPyarrow.__dlpack__r#   c                 C  s
   t jdfS r$   r%   r   r   r   r   r'   w   s    z%PandasBufferPyarrow.__dlpack_device__r(   c                 C  s   dt | j| jddœƒ d S )NzPandasBuffer[pyarrow](r&   r)   r*   )r(   r   r    r   r   r   r   r,   }   s    ýÿÿøÿzPandasBufferPyarrow.__repr__Nr-   r   r   r   r   r3   R   s   r3   )Ú
__future__r   Útypingr   r   Z*pandas.core.interchange.dataframe_protocolr   r   ÚnumpyÚnpZpyarrowÚpar   r3   r   r   r   r   Ú<module>   s   @