
    j+                         d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ  G d d      Zd	 Zh d
Z	 	 ddZ	 	 ddZ	 	 ddZddZy)    )SequenceN)_pandas_api)CodecTableconcat_tablesschema)_feather)FeatherErrorc                   .    e Zd ZdZddZddZd Zd	dZy)
FeatherDataseta  
    Encapsulates details of reading a list of Feather files.

    Parameters
    ----------
    path_or_paths : List[str]
        A list of file names
    validate_schema : bool, default True
        Check that individual file schemas are all the same / compatible
    c                      || _         || _        y N)pathsvalidate_schema)selfpath_or_pathsr   s      6/tmp/pip-target-jj7clzyk/lib/python/pyarrow/feather.py__init__zFeatherDataset.__init__+   s    "
.    Nc                 F   t        | j                  d   |      }|g| _        |j                  | _        | j                  dd D ]H  }t        ||      }| j                  r| j                  ||       | j                  j                  |       J t        | j                        S )a,  
        Read multiple feather files as a single pyarrow.Table

        Parameters
        ----------
        columns : List[str]
            Names of columns to read from the file

        Returns
        -------
        pyarrow.Table
            Content of the file as a table (of columns)
        r   columns   N)_read_table_internalr   _tablesr   r   validate_schemasappendr   )r   r   _filpathtables        r   
read_tablezFeatherDataset.read_table/   s     $DJJqM7CvkkJJqrN 	'D(w?E##%%dE2LL&		'
 T\\**r   c                     | j                   j                  |j                         s(t        d| d| j                    d|j                          y )Nz
Schema in z was different. 
z

vs

)r   equals
ValueError)r   piecer    s      r   r   zFeatherDataset.validate_schemasH   sN    {{!!%,,/z%0B $}Ju||nF G G 0r   c                 F    | j                  |      j                  |      S )a  
        Read multiple Parquet files as a single pandas DataFrame

        Parameters
        ----------
        columns : List[str]
            Names of columns to read from the file
        use_threads : bool, default True
            Use multiple threads when converting to pandas

        Returns
        -------
        pandas.DataFrame
            Content of the file as a pandas DataFrame (of columns)
        r   )use_threads)r!   	to_pandas)r   r   r'   s      r   read_pandaszFeatherDataset.read_pandasM   s*      w/99# : % 	%r   )Tr   )NT)__name__
__module____qualname____doc__r   r!   r   r)    r   r   r   r      s    	/+2G
%r   r   c                     |j                   dk(  ry |j                  t        j                         t        j                         fv rt        d|  d      t        d|  d|j                   d      )Nr   zColumn 'zg' exceeds 2GB maximum capacity of a Feather binary column. This restriction may be lifted in the futurez
' of type zU was chunked on conversion to Arrow and cannot be currently written to Feather format)
num_chunkstypeextbinarystringr$   )namecols     r   check_chunked_overflowr7   a   sw    
~~
xxCJJL#**,//8D6 *0 0 1 	1
 tfJsxxj 1@ @
 	
r   >   lz4zstduncompressedc                    |dk(  rt        j                  dt        d       t        j                  rDt        j
                  r4t        | t        j                  j                        r| j                         } t        j                  |       rp|dk(  rd}n|dk(  rd}nt        d      t        j                  | |      }|dk(  r;t        |j                  j                         D ]  \  }}	||   }
t#        |	|
        n| }|dk(  rYt%        |j&                        t%        t)        |j&                              kD  rt        d	      |t        d
      |Dt        d      |t+        j,                  d      rd}n||t.        vrt        d| dt.               	 t1        j2                  ||||||       y# t4        $ rB t        |t6              r0	 t9        j:                  |        # t8        j<                  $ r Y  w xY w w xY w)a9  
    Write a pandas.DataFrame to Feather format.

    Parameters
    ----------
    df : pandas.DataFrame or pyarrow.Table
        Data to write out as Feather format.
    dest : str
        Local destination path.
    compression : string, default None
        Can be one of {"zstd", "lz4", "uncompressed"}. The default of None uses
        LZ4 for V2 files if it is available, otherwise uncompressed.
    compression_level : int, default None
        Use a compression level particular to the chosen compressor. If None
        use the default compression level
    chunksize : int, default None
        For V2 files, the internal maximum size of Arrow RecordBatch chunks
        when writing the Arrow IPC file format. None means use the default,
        which is currently 64K
    version : int, default 2
        Feather file version. Version 2 is the current. Version 1 is the more
        limited legacy format.

        .. deprecated:: 25.0.0
           Writing Feather V1 files is deprecated. Use the default
           ``version=2`` to write Arrow IPC files instead.
    r   zFeather V1 files are deprecated as of 25.0.0 and support will be removed in a future version. Use the default version=2 to write Arrow IPC files instead.   
stacklevelFNz%Version value should either be 1 or 2)preserve_indexz'cannot serialize duplicate column namesz2Feather V1 files do not support compression optionz0Feather V1 files do not support chunksize option	lz4_framer8   zcompression="z " not supported, must be one of )compressioncompression_level	chunksizeversion)warningswarnDeprecationWarningr   have_pandas
has_sparse
isinstancepdSparseDataFrameto_denseis_data_framer$   r   from_pandas	enumerater   namesr7   lencolumn_namessetr   is_available_FEATHER_SUPPORTED_CODECSr	   write_feather	Exceptionstrosremoveerror)dfdestrA   rB   rC   rD   r?   r    ir5   r6   s              r   rW   rW   t   s   : !|- 	
 ""2{~~==>B  $ a<"N\!NDEE!!"^Da<$U\\%7%78 24Ah&tS12 !|u!!"SU-?-?)@%AAFGG" & ' '   & ' ' 5#5#5k#BK%!::}[M :''@&AC D D
ud1B)2G	E  dC 		$ 	 88 s0   F1 1G<G! G<!G74G<6G77G<c                 D     t        | |||      j                  dd|i|S )a  
    Read a pandas.DataFrame from Feather format. To read as pyarrow.Table use
    feather.read_table.

    Parameters
    ----------
    source : str file path, or file-like object
        You can use MemoryMappedFile as source, for explicitly use memory map.
    columns : sequence, optional
        Only read a specific set of columns. If not provided, all columns are
        read.
    use_threads : bool, default True
        Whether to parallelize reading using multiple threads. If false the
        restriction is used in the conversion to Pandas as well as in the
        reading from Feather format.
    memory_map : boolean, default False
        Use memory mapping when opening file on disk, when source is a str.
    **kwargs
        Additional keyword arguments passed on to `pyarrow.Table.to_pandas`.

    Returns
    -------
    df : pandas.DataFrame
        The contents of the Feather file as a pandas.DataFrame
    r   
memory_mapr'   r'   r.   )r   r(   )sourcer   r'   rb   kwargss        r   read_featherre      s<    6+ J!!*N7BNFLN Or   c                    t        j                  | ||      }|j                  dk  rt        j                  dt
        d       ||j                         S t        |t              s-t        dj                  t        |      j                              |D cg c]  }t        |       }}t        t        d |            r|j                  |      }nRt        t        d |            r|j!                  |      }n*|D cg c]  }|j                   }	}t        d| d	|	       |j                  dk  r|S t#        t%        |            |k(  r|S |j'                  |      S c c}w c c}w )
z
    Internal implementation for reading a Feather file as a pyarrow.Table.
    Emits a deprecation warning if the file is a legacy Feather V1 file.
    )use_memory_mapr'      zFeather V1 files are deprecated as of 25.0.0 and support will be removed in a future version. Consider rewriting this file in the Arrow IPC file format (Feather V2).r=   z&Columns must be a sequence but, got {}c                     | t         k(  S r   )intts    r   <lambda>z&_read_table_internal.<locals>.<lambda>  s
    c r   c                     | t         k(  S r   )rY   rk   s    r   rm   z&_read_table_internal.<locals>.<lambda>  s
    18 r   z.Columns must be indices or names. Got columns z
 of types )r	   FeatherReaderrD   rE   rF   rG   readrJ   r   	TypeErrorformatr1   r*   allmapread_indices
read_namessortedrT   select)
rc   r   rb   r'   readercolumncolumn_typesr    rl   column_type_namess
             r   r   r      s`    ##z{DF ~~9 	
 {{}gx(@W 6 679 	9 077VDL7L7
3!<01##G,	S#\2	3!!'*1=>AQZZ>> ''.iz:K9LN O 	O ~~	G		( ||G$$% 8 ?s   E ?E%c                      t        | |||      S )a  
    Read a pyarrow.Table from Feather format

    Parameters
    ----------
    source : str file path, or file-like object
        You can use MemoryMappedFile as source, for explicitly use memory map.
    columns : sequence, optional
        Only read a specific set of columns. If not provided, all columns are
        read.
    memory_map : boolean, default False
        Use memory mapping when opening file on disk, when source is a str
    use_threads : bool, default True
        Whether to parallelize reading using multiple threads.

    Returns
    -------
    table : pyarrow.Table
        The contents of the Feather file as a pyarrow.Table
    ra   )r   )rc   r   rb   r'   s       r   r!   r!   !  s    *  +5,79 9r   )NNNr<   )NTF)NFT)collections.abcr   rZ   rE   pyarrow.pandas_compatr   pyarrow.libr   r   r   r   libr2   pyarrowr	   pyarrow._featherr
   r   r7   rV   rW   re   r   r!   r.   r   r   <module>r      sr   & % 	  -0 0   )?% ?%D
  <  AE*+\~ 48!O@ ;@%)+%\9r   