ó
šxŠ\c           @   så   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 m Z d d l m Z m Z d „  Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d d d d „ Z d d d „ Z d S(   s    parquet compat iÿÿÿÿ(   t   LooseVersion(   t   catch_warnings(   t   string_types(   t   AbstractMethodError(   t	   DataFramet
   get_option(   t   get_filepath_or_buffert	   is_s3_urlc         C   s¹   |  d k r t  d ƒ }  n  |  d k rt y t ƒ  SWn t k
 rE n Xy t ƒ  SWn t k
 rd n Xt d ƒ ‚ n  |  d k r t d ƒ ‚ n  |  d k r¢ t ƒ  S|  d k rµ t ƒ  Sd S(	   s    return our implementation t   autos   io.parquet.engines}   Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
pyarrow or fastparquet is required for parquet supportt   pyarrowt   fastparquets.   engine must be one of 'pyarrow', 'fastparquet'N(   R	   R
   (   R   t   PyArrowImplt   ImportErrort   FastParquetImplt
   ValueError(   t   engine(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt
   get_engine   s$    t   BaseImplc           B   s2   e  Z d Z e d  „  ƒ Z d „  Z d d „ Z RS(   c         C   sz   t  |  t ƒ s t d ƒ ‚ n  |  j j d d h k rE t d ƒ ‚ n  t d „  |  j j Dƒ ƒ } | sv t d ƒ ‚ n  d  S(   Ns+   to_parquet only supports IO with DataFramest   stringt   unicodes%   parquet must have string column namesc         s   s*   |  ]  } | d  k	 r t | t ƒ Vq d  S(   N(   t   Nonet
   isinstanceR   (   t   .0t   name(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pys	   <genexpr>>   s   s!   Index level names must be strings(   R   R   R   t   columnst   inferred_typet   allt   indext   names(   t   dft   valid_names(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt   validate_dataframe2   s    c         K   s   t  |  ƒ ‚ d  S(   N(   R   (   t   selfR   t   patht   compressiont   kwargs(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt   writeE   s    c         K   s   t  |  ƒ ‚ d  S(   N(   R   (   R    R!   R   R#   (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt   readH   s    N(   t   __name__t
   __module__R   t   apit   staticmethodR   R$   R%   (    (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR   .   s   	R   c           B   s2   e  Z d  „  Z d d d d d „ Z d d „ Z RS(   c         C   sm   y d d  l  } d d  l } Wn t k
 r; t d ƒ ‚ n Xt | j ƒ d k  r` t d ƒ ‚ n  | |  _ d  S(   Niÿÿÿÿs‹   pyarrow is required for parquet support

you can install via conda
conda install pyarrow -c conda-forge

or via pip
pip install -U pyarrow
s   0.9.0s”   pyarrow >= 0.9.0 is required for parquet support

you can install via conda
conda install pyarrow -c conda-forge

or via pip
pip install -U pyarrow
(   R	   t   pyarrow.parquetR   R    t   __version__R(   (   R    R	   (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt   __init__N   s    t   snappyt   msc      
   K   sÈ   |  j  | ƒ t | d d ƒ\ } } } } | d  k r@ i  }	 n i | d 6}	 |  j j j | |	  }
 | d  k	 rŸ |  j j j |
 | d | d | d | | n% |  j j j |
 | d | d | | d  S(   Nt   modet   wbt   preserve_indexR"   t   coerce_timestampst   partition_cols(	   R   R   R   R(   t   Tablet   from_pandast   parquett   write_to_datasett   write_table(   R    R   R!   R"   R2   R   R3   R#   t   _t   from_pandas_kwargst   table(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR$   g   s    	c         K   sk   t  | ƒ \ } } } } t | d <|  j j j | d | | j ƒ  } | rg y | j ƒ  Wqg qg Xn  | S(   Nt   use_pandas_metadataR   (   R   t   TrueR(   R6   t
   read_tablet	   to_pandast   close(   R    R!   R   R#   R9   t   should_closet   result(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR%   |   s    
N(   R&   R'   R,   R   R$   R%   (    (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR   L   s   	R   c           B   s/   e  Z d  „  Z d d d d „ Z d d „ Z RS(   c         C   sa   y d d  l  } Wn t k
 r/ t d ƒ ‚ n Xt | j ƒ d k  rT t d ƒ ‚ n  | |  _ d  S(   Niÿÿÿÿs–   fastparquet is required for parquet support

you can install via conda
conda install fastparquet -c conda-forge

or via pip
pip install -U fastparquets   0.2.1sŸ   fastparquet >= 0.2.1 is required for parquet support

you can install via conda
conda install fastparquet -c conda-forge

or via pip
pip install -U fastparquet(   R
   R   R    R+   R(   (   R    R
   (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR,      s    R-   c         K   sÿ   |  j  | ƒ d | k r4 | d  k	 r4 t d ƒ ‚ n d | k rR | j d ƒ } n  | d  k	 rk d | d <n  t | ƒ r¥ t | d d ƒ\ } } } } d „  | d <n t | ƒ \ } } } } t d	 t ƒ - |  j j	 | | d
 | d | d | | Wd  QXd  S(   Nt   partition_onsY   Cannot use both partition_on and partition_cols. Use partition_cols for partitioning datat   hivet   file_schemeR/   R0   c         S   s   |  S(   N(    (   R!   R9   (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt   <lambda>¼   s    t	   open_witht   recordR"   t   write_index(
   R   R   R   t   popR   R   R   R=   R(   R$   (   R    R   R!   R"   R   R3   R#   R9   (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR$   ¥   s    	c         K   s”   t  | ƒ rW t | ƒ \ } } } } z" |  j j | d | j j ƒ} Wd  | j ƒ  Xn* t | ƒ \ } } } } |  j j | ƒ } | j d | |  S(   NRG   R   (   R   R   R(   t   ParquetFilet   s3t   openR@   R?   (   R    R!   R   R#   RL   R9   RA   t   parquet_file(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR%   Å   s    "N(   R&   R'   R,   R   R$   R%   (    (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyR   ‹   s   	R   R-   c      
   K   s1   t  | ƒ } | j |  | d | d | d | | S(   sÒ  
    Write a DataFrame to the parquet format.

    Parameters
    ----------
    path : str
        File path or Root Directory path. Will be used as Root Directory path
        while writing a partitioned dataset.

        .. versionchanged:: 0.24.0

    engine : {'auto', 'pyarrow', 'fastparquet'}, default 'auto'
        Parquet library to use. If 'auto', then the option
        ``io.parquet.engine`` is used. The default ``io.parquet.engine``
        behavior is to try 'pyarrow', falling back to 'fastparquet' if
        'pyarrow' is unavailable.
    compression : {'snappy', 'gzip', 'brotli', None}, default 'snappy'
        Name of the compression to use. Use ``None`` for no compression.
    index : bool, default None
        If ``True``, include the dataframe's index(es) in the file output. If
        ``False``, they will not be written to the file. If ``None``, the
        engine's default behavior will be used.

        .. versionadded 0.24.0

    partition_cols : list, optional, default None
        Column names by which to partition the dataset
        Columns are partitioned in the order they are given

        .. versionadded:: 0.24.0

    kwargs
        Additional keyword arguments passed to the engine
    R"   R   R3   (   R   R$   (   R   R!   R   R"   R   R3   R#   t   impl(    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt
   to_parquetÖ   s    $c         K   s"   t  | ƒ } | j |  d | | S(   s¦  
    Load a parquet object from the file path, returning a DataFrame.

    .. versionadded 0.21.0

    Parameters
    ----------
    path : string
        File path
    columns : list, default=None
        If not None, only these columns will be read from the file.

        .. versionadded 0.21.1
    engine : {'auto', 'pyarrow', 'fastparquet'}, default 'auto'
        Parquet library to use. If 'auto', then the option
        ``io.parquet.engine`` is used. The default ``io.parquet.engine``
        behavior is to try 'pyarrow', falling back to 'fastparquet' if
        'pyarrow' is unavailable.
    kwargs are passed to the engine

    Returns
    -------
    DataFrame
    R   (   R   R%   (   R!   R   R   R#   RO   (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt   read_parquetÿ   s    N(   t   __doc__t   distutils.versionR    t   warningsR   t   pandas.compatR   t   pandas.errorsR   t   pandasR   R   t   pandas.io.commonR   R   R   t   objectR   R   R   R   RP   RQ   (    (    (    s0   lib/python2.7/site-packages/pandas/io/parquet.pyt   <module>   s   	 ?K	(