
    Lg{'                        S SK r S SKrS SKJrJrJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJr  S SKJr   " S S\R*                  5      rSr " S S\R0                  5      r " S S	\R4                  5      r " S
 S\R8                  5      rS rS rSSS.S jr SRC                  \5      \ l"        SSS.S jr#SSS.S jr$SRC                  \5      \$l"        SSSS.S jjr%SSS.S jr&SS.S jr'g)    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                   (    \ rS rSrSrSSS.S jrSrg)RecordBatchStreamReader"   a  
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                :    [        U5      nU R                  XUS9  g )Nr    _ensure_default_ipc_read_options_open)selfsourcer   r   s       +lib/python3.12/site-packages/pyarrow/ipc.py__init__ RecordBatchStreamReader.__init__2   s    27;

6
D     __name__
__module____qualname____firstlineno____doc__r    __static_attributes__r#   r"   r   r   r   "   s     +/D E Er"   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                   F    \ rS rSrSR	                  \5      rSSS.S jrSrg)RecordBatchStreamWriterN   z0Writer for the Arrow streaming binary format

{}Nuse_legacy_formatr   c                :    [        X45      nU R                  XUS9  g Nr   _get_legacy_format_defaultr   r   sinkschemar/   r   s        r   r     RecordBatchStreamWriter.__init__S       ,->H

4
1r"   r#   	r%   r&   r'   r(   format_ipc_writer_class_docr)   r    r*   r#   r"   r   r,   r,   N   s(    f"#  ;? 2 2r"   r,   c                   ,    \ rS rSrSrSSSS.S jjrSrg)RecordBatchFileReaderX   a  
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                :    [        U5      nU R                  XX4S9  g )Nfooter_offsetr   r   r   )r   r   rB   r   r   s        r   r    RecordBatchFileReader.__init__k   s"    27;

6" 	 	=r"   r#   Nr$   r#   r"   r   r>   r>   X   s    $=d!= =r"   r>   c                   F    \ rS rSrSR	                  \5      rSSS.S jrSrg)RecordBatchFileWriterr   z1Writer to create the Arrow binary file format

{}Nr.   c                :    [        X45      nU R                  XUS9  g r1   r3   r5   s        r   r    RecordBatchFileWriter.__init__x   r9   r"   r#   r:   r#   r"   r   rF   rF   r   s(    f"#  ;? 2 2r"   rF   c                    U b  Ub  [        S5      eU(       a:  [        U[        5      (       d#  [        SR	                  [        U5      5      5      eU$ [        R                  nU c2  [        [        [        R                  R                  SS5      5      5      n [        [        [        R                  R                  SS5      5      5      (       a  [        R                  n[        U US9$ )Nz8Can provide at most one of options and use_legacy_formatz expected IpcWriteOptions, got {}ARROW_PRE_0_15_IPC_FORMAT0ARROW_PRE_1_0_METADATA_VERSION)r/   metadata_version)
ValueError
isinstancer   	TypeErrorr;   typer   V5boolintosenvirongetV4)r/   r   rN   s      r   r4   r4   }   s    $)<FH 	H	'?33>#VDM24 4&)) RZZ^^$?EFG 	C

?EFGG*--->,<> >r"   c                     U (       a8  [        U [        5      (       d#  [        SR                  [	        U 5      5      5      eU =(       d
    [        5       $ )Nzexpected IpcReadOptions, got {})rP   r   rQ   r;   rR   r2   s    r   r   r      s@    z'>::-44T']C
 	
 &n&&r"   r.   c                    [        XUUS9$ Nr.   )r,   r6   r7   r/   r   s       r   
new_streamr^      s    "45F+24 4r"   zCreate an Arrow columnar IPC stream writer instance

{}

Returns
-------
writer : RecordBatchStreamWriter
    A writer for the given sink
r   c                    [        XUS9$ )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   s      r   open_streamr`      s    & #6/:< <r"   c                    [        XUUS9$ r\   )rF   r]   s       r   new_filerb      s     3D)02 2r"   zCreate an Arrow columnar IPC file writer instance

{}

Returns
-------
writer : RecordBatchFileWriter
    A writer for the given sink
c                    [        XX#S9$ )ai  
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
rA   )r>   )r   rB   r   r   s       r   	open_filerd      s    , !2 2r"   nthreadspreserve_indexc                <   [         R                  R                  XUS9n[         R                  " 5       n[         R                  " XCR
                  5       nUR                  U5        SSS5        UR                  5       $ ! , (       d  f       UR                  5       $ = f)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.
re   N)paRecordBatchfrom_pandasBufferOutputStreamr,   r7   write_batchgetvalue)dfrf   rg   batchr6   writers         r   serialize_pandasrr      sy    ( NN&&r6D ' FE  "D		#	#D,,	765! 
8==? 
8	7==?s   A>>
BTuse_threadsc                    [         R                  " U 5      n[         R                  " U5       nUR                  5       nSSS5        WR	                  US9$ ! , (       d  f       N= f)aZ  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
Nrs   )ri   BufferReaderr   read_all	to_pandas)bufrt   buffer_readerreadertables        r   deserialize_pandasr}     sM     OOC(M		#	#M	2f! 
3??{?33 
3	2s   A
A#rD   )(rV   pyarrowri   pyarrow.libr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   lib_RecordBatchStreamReaderr   r<   _RecordBatchStreamWriterr,   _RecordBatchFileReaderr>   _RecordBatchFileWriterrF   r4   r   r^   r;   r)   r`   rb   rd   rr   r}   r#   r"   r   <module>r      s  ( 
 A A A A A Ec:: E*) .2c:: 2=C66 =42C66 2>(' 37 4	 F !   $(T <. 15d 2	 F ! 	 2Tt 26 &*$ 8 ,0 4r"   