d}i&ddlZddlZddlmZmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZGddejZdZedzdzZGdd ejZGd d ejZGd d ejZdZ dZ!dddZ"dede"_#ddddZ$ddddZ%dede%_#d ddddZ&ddddZ'dddZ(dS)!N)IpcReadOptionsIpcWriteOptions ReadStats WriteStatsMessage MessageReaderRecordBatchReader_ReadPandasMixinMetadataVersion Alignment read_messageread_record_batch read_schema read_tensor write_tensorget_record_batch_sizeget_tensor_sizec eZdZdZddddZdS)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. Noptions memory_poolcTt|}||||dS)Nr _ensure_default_ipc_read_options_open)selfsourcerrs 9C:\PYTHON\_runtimes\venv\Lib\site-packages\pyarrow/ipc.py__init__z RecordBatchStreamReader.__init__2s-27;; 67 DDDDD__name__ __module__ __qualname____doc__r r!rrr"sE  +/DEEEEEEEr!raOParameters ---------- 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. 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. zmetadata : dict | pyarrow.KeyValueMetadata, optional Key/value pairs (both must be bytes-like) that will be stored in the file footer and are retrievable via pyarrow.ipc.open_file(...).metadata.c$eZdZdeZdddZdS)RecordBatchStreamWriterz.Writer for the Arrow streaming binary format NrcTt|}||||dSNr+_get_legacy_format_defaultr)rsinkschemars rr z RecordBatchStreamWriter.__init__Xs-,W55 4 11111r!)r#r$r%_ipc_writer_class_docr&r r'r!rr*r*SsFG152222222r!r*c"eZdZdZdddddZdS)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. NrcVt|}|||||dS)N footer_offsetrrr)rrr7rrs rr zRecordBatchFileReader.__init__ps=27;; 6"   = = = = =r!Nr"r'r!rr4r4]sA$=d!=======r!r4c&eZdZdeZddddZdS)RecordBatchFileWriterz/Writer to create the Arrow binary file format NrmetadatacVt|}|||||dSNr;r.)rr0r1rr<s rr zRecordBatchFileWriter.__init__}s/,W55 48 DDDDDr!)r#r$r%_ipc_file_writer_class_docr&r r'r!rr:r:wsO   G15tEEEEEEEr!r:c|r6t|tstdt||Stj}t ttj dd}t ttj ddr tj }t||S)Nzexpected IpcWriteOptions, got ARROW_PRE_0_15_IPC_FORMAT0ARROW_PRE_1_0_METADATA_VERSION)use_legacy_formatmetadata_version) isinstancer TypeErrortyper V5boolintosenvirongetV4)rrErDs rr/r/s'?33 NLT']]LLMM M&) S ;SAA B BCC C ?EE F FGG.*- ->,< > > >>r!c|r4t|tstdt||p tS)Nzexpected IpcReadOptions, got )rFrrGrHr+s rrrsKIz'>::IGW GGHHH  &n&&&r!r+c&t|||Sr-)r*)r0r1rs r new_streamrRs "4+2 4 4 44r!z5Create an Arrow columnar IPC stream writer instance zS Returns ------- writer : RecordBatchStreamWriter A writer for the given sink rc&t|||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)rrrs r open_streamrTs"& #67/: < < <)r:)r0r1rr<s rnew_filerVs vw R R RRr!z3Create an Arrow columnar IPC file writer instance zQ Returns ------- writer : RecordBatchFileWriter A writer for the given sink c(t||||S)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 r6)r4)rr7rrs r open_filerXs%, !m[ 2 2 22r!nthreadspreserve_indexc"tj|||}tj}tj||j5}||dddn #1swxYwY|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. rYN)pa RecordBatch from_pandasBufferOutputStreamr*r1 write_batchgetvalue)dfrZr[batchr0writers rserialize_pandasrfs( N & &rH6D ' F FE " "D #D%, 7 7"65!!!""""""""""""""" ==??sA22A69A6T use_threadsctj|}tj|5}|}dddn #1swxYwY||S)aDeserialize 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 Nrg)r] BufferReaderrread_all to_pandas)bufrh buffer_readerreadertables rdeserialize_pandasrqsOC((M #M 2 2"f!!""""""""""""""" ??{? 3 33sA  AAr8))rLpyarrowr] pyarrow.librrrrrrr r r r r rrrrrrlib_RecordBatchStreamReaderrr2r?_RecordBatchStreamWriterr*_RecordBatchFileReaderr4_RecordBatchFileWriterr:r/rrRr&rTrVrXrfrqr'r!rrys#( AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEEEEEc:EEE*)$  ,,22222c:222=====C6===4EEEEEC6EEE > > >''' )-44444     $(T<<<<<.'+TSSSSS    2Tt222226&*$8,04444444r!