o
    Ìôj{'  ã                   @   s<  d dl Z d dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ d dlmZ G dd„ dejƒZdZG dd„ dejƒZG dd	„ d	ejƒZG d
d„ dejƒZdd„ Zdd„ Zdddœdd„Z d !e¡e _"dddœdd„Z#dddœdd„Z$d !e¡e$_"d#dddœdd„Z%dddœdd„Z&dd œd!d"„Z'dS )$é    N)ÚIpcReadOptionsÚIpcWriteOptionsÚ	ReadStatsÚ
WriteStatsÚMessageÚMessageReaderÚRecordBatchReaderÚ_ReadPandasMixinÚMetadataVersionÚread_messageÚread_record_batchÚread_schemaÚread_tensorÚwrite_tensorÚget_record_batch_sizeÚget_tensor_sizec                   @   s    e Zd ZdZdddœdd„ZdS )ÚRecordBatchStreamReadera  
    Reader for the Arrow streaming binary format.

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
        If you want to use memory map use MemoryMappedFile as source.
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC deserialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.
    N©ÚoptionsÚmemory_poolc                C   s   t |ƒ}| j|||d� d S )Nr   ©Ú _ensure_default_ipc_read_optionsÚ_open)ÚselfÚsourcer   r   © r   ú^/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/pyarrow/ipc.pyÚ__init__2   s   z RecordBatchStreamReader.__init__©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   "   s    r   aN  Parameters
----------
sink : str, pyarrow.NativeFile, or file-like Python object
    Either a file path, or a writable file object.
schema : pyarrow.Schema
    The Arrow schema for data to be written to the file.
use_legacy_format : bool, default None
    Deprecated in favor of setting options. Cannot be provided with
    options.

    If None, False will be used unless this default is overridden by
    setting the environment variable ARROW_PRE_0_15_IPC_FORMAT=1
options : pyarrow.ipc.IpcWriteOptions
    Options for IPC serialization.

    If None, default values will be used: the legacy format will not
    be used unless overridden by setting the environment variable
    ARROW_PRE_0_15_IPC_FORMAT=1, and the V5 metadata version will be
    used unless overridden by setting the environment variable
    ARROW_PRE_1_0_METADATA_VERSION=1.c                   @   ó&   e Zd Zd e¡Zdddœdd„ZdS )ÚRecordBatchStreamWriterz0Writer for the Arrow streaming binary format

{}N©Úuse_legacy_formatr   c                C   ó   t ||ƒ}| j|||d� d S ©N©r   ©Ú_get_legacy_format_defaultr   ©r   ÚsinkÚschemar&   r   r   r   r   r   S   ó   
z RecordBatchStreamWriter.__init__©r   r    r!   ÚformatÚ_ipc_writer_class_docr"   r   r   r   r   r   r$   N   s
    þr$   c                   @   s"   e Zd ZdZddddœdd„ZdS )ÚRecordBatchFileReadera»  
    Class for reading Arrow record batch data from the Arrow binary file format

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
        If you want to use memory map use MemoryMappedFile as source.
    footer_offset : int, default None
        If the file is embedded in some larger file, this is the byte offset to
        the very end of the file data
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC serialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.
    Nr   c                C   s   t |ƒ}| j||||d� d S )N©Úfooter_offsetr   r   r   )r   r   r5   r   r   r   r   r   r   k   s   
ÿzRecordBatchFileReader.__init__©Nr   r   r   r   r   r3   X   s
    ÿr3   c                   @   r#   )ÚRecordBatchFileWriterz1Writer to create the Arrow binary file format

{}Nr%   c                C   r'   r(   r*   r,   r   r   r   r   x   r/   zRecordBatchFileWriter.__init__r0   r   r   r   r   r7   r   s
    þr7   c                 C   sˆ   | d ur|d urt dƒ‚|rt|tƒstd t|ƒ¡ƒ‚|S tj}| d u r0tt	t
j dd¡ƒƒ} tt	t
j dd¡ƒƒr>tj}t| |d�S )Nz8Can provide at most one of options and use_legacy_formatz expected IpcWriteOptions, got {}ZARROW_PRE_0_15_IPC_FORMATÚ0ZARROW_PRE_1_0_METADATA_VERSION)r&   Úmetadata_version)Ú
ValueErrorÚ
isinstancer   Ú	TypeErrorr1   Útyper
   ÚV5ÚboolÚintÚosÚenvironÚgetÚV4)r&   r   r9   r   r   r   r+   }   s&   ÿ

ÿÿÿr+   c                 C   s*   | rt | tƒstd t| ƒ¡ƒ‚| ptƒ S )Nzexpected IpcReadOptions, got {})r;   r   r<   r1   r=   r)   r   r   r   r   ‘   s
   ÿ
r   r%   c                C   ó   t | |||d�S ©Nr%   )r$   ©r-   r.   r&   r   r   r   r   Ú
new_stream™   ó   þrH   zŠCreate an Arrow columnar IPC stream writer instance

{}

Returns
-------
writer : RecordBatchStreamWriter
    A writer for the given sink
r   c                C   s   t | ||d�S )a  
    Create reader for Arrow streaming format.

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC serialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.

    Returns
    -------
    reader : RecordBatchStreamReader
        A reader for the given source
    r   )r   )r   r   r   r   r   r   Úopen_stream«   s   ÿrJ   c                C   rE   rF   )r7   rG   r   r   r   Únew_fileÂ   rI   rK   z†Create an Arrow columnar IPC file writer instance

{}

Returns
-------
writer : RecordBatchFileWriter
    A writer for the given sink
c                C   rE   )a±  
    Create reader for Arrow file format.

    Parameters
    ----------
    source : bytes/buffer-like, pyarrow.NativeFile, or file-like Python object
        Either an in-memory buffer, or a readable file object.
    footer_offset : int, default None
        If the file is embedded in some larger file, this is the byte offset to
        the very end of the file data.
    options : pyarrow.ipc.IpcReadOptions
        Options for IPC serialization.
        If None, default values will be used.
    memory_pool : MemoryPool, default None
        If None, default memory pool is used.

    Returns
    -------
    reader : RecordBatchFileReader
        A reader for the given source
    r4   )r3   )r   r5   r   r   r   r   r   Ú	open_fileÔ   s   þrL   ©ÚnthreadsÚpreserve_indexc                C   s`   t jj| ||d�}t  ¡ }t  ||j¡�}| |¡ W d  ƒ | ¡ S 1 s'w   Y  | ¡ S )a   
    Serialize a pandas DataFrame into a buffer protocol compatible object.

    Parameters
    ----------
    df : pandas.DataFrame
    nthreads : int, default None
        Number of threads to use for conversion to Arrow, default all CPUs.
    preserve_index : bool, default None
        The default of None will store the index as a column, except for
        RangeIndex which is stored as metadata only. If True, always
        preserve the pandas index data as a column. If False, no index
        information is saved and the result will have a default RangeIndex.

    Returns
    -------
    buf : buffer
        An object compatible with the buffer protocol.
    rM   N)ÚpaÚRecordBatchÚfrom_pandasÚBufferOutputStreamr$   r.   Úwrite_batchÚgetvalue)ÚdfrN   rO   Úbatchr-   Úwriterr   r   r   Úserialize_pandasï   s   
ÿ
ÿþrY   T©Úuse_threadsc                C   sH   t  | ¡}t  |¡�}| ¡ }W d  ƒ n1 sw   Y  |j|d�S )a†  Deserialize a buffer protocol compatible object into a pandas DataFrame.

    Parameters
    ----------
    buf : buffer
        An object compatible with the buffer protocol.
    use_threads : bool, default True
        Whether to parallelize the conversion using multiple threads.

    Returns
    -------
    df : pandas.DataFrame
        The buffer deserialized as pandas DataFrame
    NrZ   )rP   ÚBufferReaderr   Úread_allÚ	to_pandas)Úbufr[   Zbuffer_readerÚreaderÚtabler   r   r   Údeserialize_pandas  s
   

ÿrb   r6   )(rA   ÚpyarrowrP   Úpyarrow.libr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   ÚlibÚ_RecordBatchStreamReaderr   r2   Ú_RecordBatchStreamWriterr$   Ú_RecordBatchFileReaderr3   Ú_RecordBatchFileWriterr7   r+   r   rH   r1   r"   rJ   rK   rL   rY   rb   r   r   r   r   Ú<module>   s.   H
	÷	÷