
x\c           @  s  d  Z  d d l m Z m Z d d l m Z d d l m Z m Z m Z d d l	 m
 Z
 d d l Z d d l Z d d l Z d d l j j Z d d l m Z m Z m Z m Z m Z d d l m Z m Z m Z d d	 l m Z d d
 l m Z d d l  m! Z! m" Z" d d l# m$ Z$ d d l% m& Z& d e' f d     YZ( d e) f d     YZ* e+ a, d   Z- d   Z. d   Z/ e+ e+ d  Z0 d   Z1 e+ e2 e+ d  Z3 e+ e+ d  Z4 e+ e+ e2 e+ e+ e+ d  Z5 e+ e2 e+ e+ e+ d  Z6 e+ e2 e+ e+ e+ e+ d  Z7 e+ d e2 e+ e+ e+ e+ d  Z8 e+ d  Z9 e9 Z: d   Z; e+ e+ e< d   Z= d! e$ f d"     YZ> d# e$ f d$     YZ? d% e? f d&     YZ@ i d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d+ d3 6ZA d4   ZB d5   ZC d6 ZD d7 e> f d8     YZE d9 e? f d:     YZF e+ e+ e+ d;  ZG d S(<   s|   
Collection of query wrappers / abstractions to both facilitate data
retrieval and to reduce dependency on DB-specific API.
i(   t   divisiont   print_function(   t   contextmanager(   t   datet   datetimet   time(   t   partialN(   t   mapt   raise_with_tracebackt   string_typest	   text_typet   zip(   t   is_datetime64tz_dtypet   is_dict_liket   is_list_like(   t   DatetimeTZDtype(   t   isna(   t	   DataFramet   Series(   t   PandasObject(   t   to_datetimet   SQLAlchemyRequiredc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR      s   t   DatabaseErrorc           B  s   e  Z RS(    (   R   R   (    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR   #   s   c         C  s   t  d  k r y d d  l } t a  d d l m } | j } | |  | d  k  r d d l m } d d l m	 } | | d  d    } n  Wq t
 k
 r t a  q Xn  t  r d d  l } t |  | j j  St Sd  S(   Ni(   t   LooseVersions   0.8.2(   t
   BigInteger(   t   compilest   sqlitec         [  s   d S(   Nt   INTEGER(    (   t   type_t   compilert   kw(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   compile_big_int_sqlite=   s    (   t   _SQLALCHEMY_INSTALLEDt   Nonet
   sqlalchemyt   Truet   distutils.versionR   t   __version__R   t   sqlalchemy.ext.compilerR   t   ImportErrort   Falset
   isinstancet   enginet   Connectable(   t   conR$   R   t   verR   R   R!   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _is_sqlalchemy_connectable-   s     	c         C  sN   |  g } | d k	 rJ t | d  r4 | | g 7} qJ | t |  g 7} n  | S(   s9   Convert SQL and params args to DBAPI2.0 compliant format.t   keysN(   R#   t   hasattrt   list(   t   sqlt   paramst   args(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _convert_paramsJ   s    	c         C  sL   |  t  k s$ |  d k s$ |  t k r- g  }  n t |  d  sH |  g }  n  |  S(   s3   Process parse_dates argument for read_sql functionst   __iter__N(   R%   R#   R*   R2   (   t   parse_dates(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _process_parse_dates_argumentU   s
    $	c      	   C  s   t  | t  r" t |  d d | S| d  k rg t |  j j t j  s^ t |  j j t j	  rg d } n  | d k r t |  d d d | d | St
 |   r t |  d t St |  d d d | d | Sd  S(   Nt   errorst   ignoret   st   Dt   dt   ht   mt   mst   ust   nst   coercet   unitt   utct   format(   R>   R?   R@   RA   R=   RB   RC   RD   (   R+   t   dictR   R#   t
   issubclasst   dtypet   typet   npt   floatingt   integerR   R%   (   t   colRG   RH   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _handle_date_column`   s    $	c         C  s   t  |  } xs |  j   D]e \ } } t |  s= | | k r y | | } Wn t k
 rd d } n Xt | d | |  | <q q W|  S(   sz   
    Force non-datetime columns to be read as such.
    Supports both string formatted and integer timestamp columns.
    RH   N(   R:   t	   iteritemsR   t	   TypeErrorR#   RQ   (   t
   data_frameR9   t   col_namet   df_colt   fmt(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _parse_date_columnss   s    
c         C  sP   t  j |  d | d | } t | |  } | d k	 rL | j | d t n  | S(   s(   Wrap result set of query in a DataFrame.t   columnst   coerce_floatt   inplaceN(   R   t   from_recordsRX   R#   t	   set_indexR%   (   t   dataRY   t	   index_colRZ   R9   t   frame(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _wrap_result   s    	c         C  sI   | d k r t |  } n t | d t } t |  |  } | j |   S(   sY  
    Execute the given SQL query using the provided connection object.

    Parameters
    ----------
    sql : string
        SQL query to be executed.
    con : SQLAlchemy connectable(engine/connection) or sqlite3 connection
        Using SQLAlchemy makes it possible to use any DB supported by the
        library.
        If a DBAPI2 object, only sqlite3 is supported.
    cur : deprecated, cursor is obtained from connection, default: None
    params : list or tuple, optional, default: None
        List of parameters to pass to execute method.

    Returns
    -------
    Results Iterable
    t	   is_cursorN(   R#   t   pandasSQL_builderR%   R7   t   execute(   R4   R.   t   curR5   t
   pandas_sqlR6   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRd      s
    c         C  s  t  |  } t |  s' t d   n  d d l } d d l m }	 |	 | d | }
 y |
 j d |  g d t  Wn/ | j j	 k
 r t
 d j d	 |     n Xt | d
 |
 } | j |  d | d | d | d | d | } | d k	 r | St
 d j d	 |   |   d S(   sW  Read SQL database table into a DataFrame.

    Given a table name and a SQLAlchemy connectable, returns a DataFrame.
    This function does not support DBAPI connections.

    Parameters
    ----------
    table_name : string
        Name of SQL table in database.
    con : SQLAlchemy connectable (or database string URI)
        SQLite DBAPI connection mode not supported.
    schema : string, default None
        Name of SQL schema in database to query (if database flavor
        supports this). Uses default schema if None (default).
    index_col : string or list of strings, optional, default: None
        Column(s) to set as index(MultiIndex).
    coerce_float : boolean, default True
        Attempts to convert values of non-string, non-numeric objects (like
        decimal.Decimal) to floating point. Can result in loss of Precision.
    parse_dates : list or dict, default: None
        - List of column names to parse as dates.
        - Dict of ``{column_name: format string}`` where format string is
          strftime compatible in case of parsing string times or is one of
          (D, s, ns, ms, us) in case of parsing integer timestamps.
        - Dict of ``{column_name: arg dict}``, where the arg dict corresponds
          to the keyword arguments of :func:`pandas.to_datetime`
          Especially useful with databases without native Datetime support,
          such as SQLite.
    columns : list, default: None
        List of column names to select from SQL table
    chunksize : int, default None
        If specified, returns an iterator where `chunksize` is the number of
        rows to include in each chunk.

    Returns
    -------
    DataFrame

    See Also
    --------
    read_sql_query : Read SQL query into a DataFrame.
    read_sql

    Notes
    -----
    Any datetime values with time zone information will be converted to UTC.
    s9   read_sql_table only supported for SQLAlchemy connectable.iN(   t   MetaDatat   schemat   onlyt   viewss   Table {name} not foundt   namet   metaR_   RZ   R9   RY   t	   chunksize(   t   _engine_builderR0   t   NotImplementedErrorR$   t   sqlalchemy.schemaRg   t   reflectR%   t   exct   InvalidRequestErrort
   ValueErrorRH   t   SQLDatabaset
   read_tableR#   (   t
   table_nameR.   Rh   R_   RZ   R9   RY   Rm   R$   Rg   Rl   Rf   t   table(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   read_sql_table   s"    3c         C  s7   t  |  } | j |  d | d | d | d | d | S(   s,	  Read SQL query into a DataFrame.

    Returns a DataFrame corresponding to the result set of the query
    string. Optionally provide an `index_col` parameter to use one of the
    columns as the index, otherwise default integer index will be used.

    Parameters
    ----------
    sql : string SQL query or SQLAlchemy Selectable (select or text object)
        SQL query to be executed.
    con : SQLAlchemy connectable(engine/connection), database string URI,
        or sqlite3 DBAPI2 connection
        Using SQLAlchemy makes it possible to use any DB supported by that
        library.
        If a DBAPI2 object, only sqlite3 is supported.
    index_col : string or list of strings, optional, default: None
        Column(s) to set as index(MultiIndex).
    coerce_float : boolean, default True
        Attempts to convert values of non-string, non-numeric objects (like
        decimal.Decimal) to floating point. Useful for SQL result sets.
    params : list, tuple or dict, optional, default: None
        List of parameters to pass to execute method.  The syntax used
        to pass parameters is database driver dependent. Check your
        database driver documentation for which of the five syntax styles,
        described in PEP 249's paramstyle, is supported.
        Eg. for psycopg2, uses %(name)s so use params={'name' : 'value'}
    parse_dates : list or dict, default: None
        - List of column names to parse as dates.
        - Dict of ``{column_name: format string}`` where format string is
          strftime compatible in case of parsing string times, or is one of
          (D, s, ns, ms, us) in case of parsing integer timestamps.
        - Dict of ``{column_name: arg dict}``, where the arg dict corresponds
          to the keyword arguments of :func:`pandas.to_datetime`
          Especially useful with databases without native Datetime support,
          such as SQLite.
    chunksize : int, default None
        If specified, return an iterator where `chunksize` is the number of
        rows to include in each chunk.

    Returns
    -------
    DataFrame

    See Also
    --------
    read_sql_table : Read SQL database table into a DataFrame.
    read_sql

    Notes
    -----
    Any datetime values with time zone information parsed via the `parse_dates`
    parameter will be converted to UTC.
    R_   R5   RZ   R9   Rm   (   Rc   t
   read_query(   R4   R.   R_   RZ   R5   R9   Rm   Rf   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   read_sql_query   s    7c   
      C  s   t  |  } t | t  rF | j |  d | d | d | d | d | Sy | j |   }	 Wn t k
 rr t }	 n X|	 r | j j d |  g  | j	 |  d | d | d | d | d | S| j |  d | d | d | d | d | Sd S(	   sK
  
    Read SQL query or database table into a DataFrame.

    This function is a convenience wrapper around ``read_sql_table`` and
    ``read_sql_query`` (for backward compatibility). It will delegate
    to the specific function depending on the provided input. A SQL query
    will be routed to ``read_sql_query``, while a database table name will
    be routed to ``read_sql_table``. Note that the delegated function might
    have more specific notes about their functionality not listed here.

    Parameters
    ----------
    sql : string or SQLAlchemy Selectable (select or text object)
        SQL query to be executed or a table name.
    con : SQLAlchemy connectable (engine/connection) or database string URI
        or DBAPI2 connection (fallback mode)

        Using SQLAlchemy makes it possible to use any DB supported by that
        library. If a DBAPI2 object, only sqlite3 is supported.
    index_col : string or list of strings, optional, default: None
        Column(s) to set as index(MultiIndex).
    coerce_float : boolean, default True
        Attempts to convert values of non-string, non-numeric objects (like
        decimal.Decimal) to floating point, useful for SQL result sets.
    params : list, tuple or dict, optional, default: None
        List of parameters to pass to execute method.  The syntax used
        to pass parameters is database driver dependent. Check your
        database driver documentation for which of the five syntax styles,
        described in PEP 249's paramstyle, is supported.
        Eg. for psycopg2, uses %(name)s so use params={'name' : 'value'}
    parse_dates : list or dict, default: None
        - List of column names to parse as dates.
        - Dict of ``{column_name: format string}`` where format string is
          strftime compatible in case of parsing string times, or is one of
          (D, s, ns, ms, us) in case of parsing integer timestamps.
        - Dict of ``{column_name: arg dict}``, where the arg dict corresponds
          to the keyword arguments of :func:`pandas.to_datetime`
          Especially useful with databases without native Datetime support,
          such as SQLite.
    columns : list, default: None
        List of column names to select from SQL table (only used when reading
        a table).
    chunksize : int, default None
        If specified, return an iterator where `chunksize` is the
        number of rows to include in each chunk.

    Returns
    -------
    DataFrame

    See Also
    --------
    read_sql_table : Read SQL database table into a DataFrame.
    read_sql_query : Read SQL query into a DataFrame.
    R_   R5   RZ   R9   Rm   Ri   RY   N(
   Rc   R+   t   SQLiteDatabaseRz   t	   has_tablet	   ExceptionR*   Rl   Rq   Rv   (
   R4   R.   R_   RZ   R5   R9   RY   Rm   Rf   t   _is_table_name(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   read_sql=  s&    9
t   failc
         C  s   | d k r$ t  d j |    n  t | d | }
 t |  t  rT |  j   }  n t |  t  sr t d   n  |
 j |  | d | d | d	 | d | d
 | d | d |	 d S(   sK  
    Write records stored in a DataFrame to a SQL database.

    Parameters
    ----------
    frame : DataFrame, Series
    name : string
        Name of SQL table.
    con : SQLAlchemy connectable(engine/connection) or database string URI
        or sqlite3 DBAPI2 connection
        Using SQLAlchemy makes it possible to use any DB supported by that
        library.
        If a DBAPI2 object, only sqlite3 is supported.
    schema : string, default None
        Name of SQL schema in database to write to (if database flavor
        supports this). If None, use default schema (default).
    if_exists : {'fail', 'replace', 'append'}, default 'fail'
        - fail: If table exists, do nothing.
        - replace: If table exists, drop it, recreate it, and insert data.
        - append: If table exists, insert data. Create if does not exist.
    index : boolean, default True
        Write DataFrame index as a column.
    index_label : string or sequence, default None
        Column label for index column(s). If None is given (default) and
        `index` is True, then the index names are used.
        A sequence should be given if the DataFrame uses MultiIndex.
    chunksize : int, default None
        If not None, then rows will be written in batches of this size at a
        time.  If None, all rows will be written at once.
    dtype : single SQLtype or dict of column name to SQL type, default None
        Optional specifying the datatype for columns. The SQL type should
        be a SQLAlchemy type, or a string for sqlite3 fallback connection.
        If all columns are of the same type, one single value can be used.
    method : {None, 'multi', callable}, default None
        Controls the SQL insertion clause used:

        - None : Uses standard SQL ``INSERT`` clause (one per row).
        - 'multi': Pass multiple values in a single ``INSERT`` clause.
        - callable with signature ``(pd_table, conn, keys, data_iter)``.

        Details and a sample callable implementation can be found in the
        section :ref:`insert method <io.sql.method>`.

        .. versionadded:: 0.24.0
    R   t   replacet   appends    '{0}' is not valid for if_existsRh   s9   'frame' argument should be either a Series or a DataFramet	   if_existst   indext   index_labelRm   RK   t   methodN(   R   R   R   (	   Rt   RH   Rc   R+   R   t   to_frameR   Ro   t   to_sql(   R`   Rk   R.   Rh   R   R   R   Rm   RK   R   Rf   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    /c         C  s   t  | d | } | j |   S(   s-  
    Check if DataBase has named table.

    Parameters
    ----------
    table_name: string
        Name of SQL table.
    con: SQLAlchemy connectable(engine/connection) or sqlite3 DBAPI2 connection
        Using SQLAlchemy makes it possible to use any DB supported by that
        library.
        If a DBAPI2 object, only sqlite3 is supported.
    schema : string, default None
        Name of SQL schema in database to write to (if database flavor supports
        this). If None, use default schema (default).

    Returns
    -------
    boolean
    Rh   (   Rc   R}   (   Rw   R.   Rh   Rf   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR}     s    c         C  sS   t  |  t  rO y d d l } Wn t k
 r8 t a qO X| j |   }  |  Sn  |  S(   sw   
    Returns a SQLAlchemy engine from a URI (if con is a string)
    else it just return con without modifying it.
    iN(   R+   R	   R$   R)   R*   R"   t   create_engine(   R.   R$   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRn     s    
c         C  s`   t  |   }  t |   r. t |  d | d | St |  t  rL t d   n t |  d | Sd S(   sm   
    Convenience function to return the correct PandasSQL subclass based on the
    provided parameters.
    Rh   Rl   s.   Using URI string without sqlalchemy installed.Rb   N(   Rn   R0   Ru   R+   R	   R)   R|   (   R.   Rh   Rl   Rb   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRc     s    t   SQLTablec        	   B  s   e  Z d  Z d e d d d d d d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d d d  Z e d d  Z e d d d d  Z d   Z d   Z d   Z d d  Z d   Z d   Z RS(   s   
    For mapping Pandas tables to SQL tables.
    Uses fact that table is reflected by SQLAlchemy to
    do better type conversions.
    Also holds various flags needed to avoid having to
    pass them between functions all the time.
    R   t   pandasc         C  s   | |  _  | |  _ | |  _ | |  _ |  j | |  |  _ | |  _ | |  _ |	 |  _ |
 |  _	 | d  k	 r{ |  j   |  _ n |  j j |  j  |  j  |  _ |  j d  k r t d j d |    n  d  S(   Ns   Could not init table '{name}'Rk   (   Rk   t   pd_sqlt   prefixR`   t   _index_nameR   Rh   R   R1   RK   R#   t   _create_table_setupRx   t	   get_tableRt   RH   (   t   selfRk   t   pandas_sql_engineR`   R   R   R   R   Rh   R1   RK   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   __init__  s    								c         C  s   |  j  j |  j |  j  S(   N(   R   R}   Rk   Rh   (   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   exists/  s    c         C  s2   d d l  m } t | |  j  j |  j j   S(   Ni(   t   CreateTable(   Rp   R   t   strRx   t   compileR   t   connectable(   R   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt
   sql_schema2  s    c         C  s,   |  j  j |  j j  |  _  |  j  j   d  S(   N(   Rx   t
   tometadataR   Rl   t   create(   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _execute_create6  s    c         C  s   |  j    r |  j d k r9 t d j d |  j    q |  j d k rn |  j j |  j |  j  |  j   q |  j d k r q t d j |  j    n
 |  j   d  S(   NR   s   Table '{name}' already exists.Rk   R   R   s    '{0}' is not valid for if_exists(	   R   R   Rt   RH   Rk   R   t
   drop_tableRh   R   (   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR   ;  s    c         C  sE   g  | D] } t  t | |   ^ q } | j |  j j   |  d S(   s3  Execute SQL statement inserting data

        Parameters
        ----------
        conn : sqlalchemy.engine.Engine or sqlalchemy.engine.Connection
        keys : list of str
           Column names
        data_iter : generator of list
           Each item contains a list of values to be inserted
        N(   RI   R   Rd   Rx   t   insert(   R   t   connR1   t	   data_itert   rowR^   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _execute_insertK  s    (c         C  sE   g  | D] } t  t | |   ^ q } | j |  j j |   d S(   s   Alternative to _execute_insert for DBs support multivalue INSERT.

        Note: multi-value insert is usually faster for analytics DBs
        and tables containing a few columns
        but performance degrades quickly with increase of columns.
        N(   RI   R   Rd   Rx   R   (   R   R   R1   R   R   R^   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _execute_insert_multiY  s    (c         C  s  |  j  d  k	 ro |  j j   } |  j  | j  _ y | j d t  Wqx t k
 rk } t d j |    qx Xn	 |  j } t	 t
 t | j   } t |  } d  g | } | j j } x | D] } | j r| j r | j j   } t j | d d } q4| j j d  j t  } n t j | j   d t } | j rVt |  }	 d  | |	 <n  x* t | j |  D] \ }
 } | | |
 <qiWq W| | f S(   NR[   s$   duplicate name in index/columns: {0}t   axisi    s   M8[us]RK   (   R   R#   R`   t   copyt   namest   reset_indexR%   Rt   RH   R3   R   R
   RY   t   lent   _datat   blockst   is_datetimet   is_datetimetzt   valuest   to_pydatetimeRM   t   expand_dimst   astypet   objectt   arrayt
   get_valuest   _can_hold_naR   R   t   mgr_locs(   R   t   tempt   errt   column_namest   ncolst	   data_listR   t   bR?   t   maskt   col_locRP   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   insert_datac  s4    				c         C  sr  | d  k r |  j } nK | d k r0 |  j } n3 t |  rN t | |   } n t d j |    |  j   \ } } t |  j	  } | d k r d  S| d  k r | } n | d k r t d   n  t
 | |  d } |  j j    } x{ t |  D]m }	 |	 | }
 t |	 d | |  } |
 | k r.Pn  t g  | D] } | |
 | !^ q8  } | | | |  q WWd  QXd  S(   Nt   multis   Invalid parameter `method`: {}i    s%   chunksize argument should be non-zeroi   (   R#   R   R   t   callableR   Rt   RH   R   R   R`   t   intR   t   run_transactiont   ranget   minR   (   R   Rm   R   t   exec_insertR1   R   t   nrowst   chunksR   t   it   start_it   end_it   arrt
   chunk_iter(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s0    	
&c         c  s   x t  r | j |  } | s" Pq t j | d | d | |  _ |  j d |  |  j d k	 r{ |  j j |  j d t  n  |  j Vq Wd S(   s,   Return generator through chunked result set.RY   RZ   R9   R[   N(	   R%   t	   fetchmanyR   R\   R`   t   _harmonize_columnsR   R#   R]   (   R   t   resultRm   RY   RZ   R9   R^   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _query_iterator  s    	c         C  sw  | d  k	 r t |  d k r d d l m } g  | D] } |  j j | ^ q5 } |  j d  k	 r g  |  j d  d  d  D]" } | j d |  j j |  ^ qw n  | |  }	 n |  j j   }	 |  j j	 |	  }
 |
 j
   } | d  k	 r|  j |
 | | d | d | S|
 j   } t j | d | d | |  _ |  j d |  |  j d  k	 rl|  j j |  j d t n  |  j Sd  S(   Ni    i(   t   selectRZ   R9   RY   R[   (   R#   R   R$   R   Rx   t   cR   R   R   Rd   R1   R   t   fetchallR   R\   R`   R   R]   R%   (   R   RZ   R9   RY   Rm   R   t   nt   colst   idxt
   sql_selectR   R   R^   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   read  s(    #@c         C  s(  | t  k r |  j j j } | d  k	 rs t | t  sB | g } n  t |  | k rl t d j	 |    qs | Sn  | d k r d |  j j
 k r |  j j j d  k r d g Sg  t |  j j j  D]- \ } } | d  k	 r | n d j	 |  ^ q Sn- t | t  r| g St | t  r | Sd  Sd  S(   NsC   Length of 'index_label' should match number of levels, which is {0}i   R   s	   level_{0}(   R%   R`   R   t   nlevelsR#   R+   R3   R   Rt   RH   RY   Rk   t	   enumerateR   R	   (   R   R   R   R   R   t   l(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s(    Gc         C  s   g  } |  j  d  k	 ro xW t |  j   D]C \ } } | |  j j  j |   } | j t |  | t f  q% Wn  | g  t t	 |  j j
   D]A } t |  j j
 |  | |  j j d  d   | f  t f ^ q 7} | S(   N(   R   R#   R   R`   t   _get_level_valuesR   R
   R%   R   R   RY   t   ilocR*   (   R   t   dtype_mappert   column_names_and_typesR   t	   idx_labelt   idx_type(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _get_column_names_and_types   s    ^c         C  s  d d l  m } m } m } |  j |  j  } g  | D]$ \ } } } | | | d | ^ q5 } |  j d  k	 r t |  j  s |  j g }	 n	 |  j }	 | d |  j	 d |	  }
 | j
 |
  n  |  j p |  j j j } d d l m } | |  j d | } | |  j	 | d | | S(   Ni(   t   Tablet   Columnt   PrimaryKeyConstraintR   Rk   t   _pk(   Rg   Rh   (   R$   R   R   R   R   t   _sqlalchemy_typeR1   R#   R   Rk   R   Rh   R   Rl   Rp   Rg   (   R   R   R   R   R   Rk   t   typt   is_indexRY   R1   t   pkcRh   Rg   Rl   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    .	c         C  s  t  |  } xy|  j j D]k} | j } yH|  j | } | | k r y | | } Wn t k
 rk d } n Xt | d | |  j | <w n  |  j | j	  } | t
 k s | t k s | t k r | t k } t | d | |  j | <n | t k r| j | d t |  j | <n[ t |  | j   k ro| t j d  k sM| t k ro| j | d t |  j | <qon  Wq t k
 rq Xq Wd S(   s  
        Make the DataFrame's column types align with the SQL table
        column types.
        Need to work around limited NA value support. Floats are always
        fine, ints must always be floats if there are Null values.
        Booleans are hard because converting bool column with None replaces
        all Nones with false. Therefore only convert bool if there are no
        NA values.
        Datetimes should already be converted to np.datetime64 if supported,
        but here we also force conversion if required.
        RH   RG   R   t   int64N(   R:   Rx   RY   Rk   R`   RS   R#   RQ   t
   _get_dtypeRL   R   R   R   t   floatR   R*   R   t   countRM   RK   t   boolt   KeyError(   R   R9   t   sql_colRU   RV   RW   t   col_typeRG   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR   -  s4    	
! c         C  s  |  j  p i  } | j | k r, |  j  | j St j | d t } d d l m } m } m } m	 } m
 } m }	 m }
 m } m } | d k s | d k r y# | j j d  k	 r | d t  SWn- t k
 r | j d  k	 r | d t  Sn X|	 S| d k rt j d t d	 d
 | S| d k rN| j  d k r>| d d  S| d d  Snq | d k rt| j  d k rm| S| SnK | d k r| S| d k r|
 S| d k r| S| d k rt d   n  | S(   Nt   skipnai(	   R   t   Integert   Floatt   Textt   Booleant   DateTimet   Datet   Timet	   TIMESTAMPt
   datetime64R   t   timezonet   timedelta64sl   the 'timedelta' type is not supported, and will be written as integer values (ns frequency) to the database.t
   stackleveli   RN   t   float32t	   precisioni   i5   RO   t   int32t   booleanR   R   t   complexs   Complex datatypes not supported(   RK   Rk   t   libt   infer_dtypeR%   t   sqlalchemy.typesR   R   R   R   R   R   R   R   R   t   dtt   tzR#   t   AttributeErrort   warningst   warnt   UserWarningRt   (   R   RP   RK   R   R   R   R   R   R   R   R   R   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR   _  sD    @	c         C  s   d d l  m } m } m } m } m } m } t | |  rA t St | |  r] t	 j
 d  St | |  r} | j sy t St St | |  r t St | |  r t St | |  r t St S(   Ni(   R   R   R   R   R   R   R   (   R  R   R   R   R   R   R   R+   R   RM   RK   R   R   R   R   R   R   (   R   t   sqltypeR   R   R   R   R   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s     .	N(   R   R   t   __doc__R#   R%   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s,   							
	)$				2	3t	   PandasSQLc           B  s    e  Z d  Z d   Z d   Z RS(   s7   
    Subclasses Should define read_sql and to_sql.
    c         O  s   t  d   d  S(   NsM   PandasSQL must be created with an SQLAlchemy connectable or sqlite connection(   Rt   (   R   R6   t   kwargs(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    c         O  s   t  d   d  S(   NsM   PandasSQL must be created with an SQLAlchemy connectable or sqlite connection(   Rt   (   R   R6   R  (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    (   R   R   R  R   R   (    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR    s   	Ru   c           B  s   e  Z d  Z d d d  Z e d    Z d   Z d e d d d d d  Z	 e
 d e d d   Z d e d d d d  Z e Z d e d d d d d d  Z e d	    Z d d
  Z d d  Z d d  Z d d d  Z RS(   s  
    This class enables conversion between DataFrame and SQL databases
    using SQLAlchemy to handle DataBase abstraction.

    Parameters
    ----------
    engine : SQLAlchemy connectable
        Connectable to connect with the database. Using SQLAlchemy makes it
        possible to use any DB supported by that library.
    schema : string, default None
        Name of SQL schema in database to write to (if database flavor
        supports this). If None, use default schema (default).
    meta : SQLAlchemy MetaData object, default None
        If provided, this MetaData object is used instead of a newly
        created. This allows to specify database flavor specific
        arguments in the MetaData object.

    c         C  sD   | |  _  | s7 d d l m } | |  j  d | } n  | |  _ d  S(   Ni(   Rg   Rh   (   R   Rp   Rg   Rl   (   R   R,   Rh   Rl   Rg   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s
    	c         c  s;   |  j  j   & } t | d  r) | Vn |  j  VWd  QXd  S(   NRd   (   R   t   beginR2   (   R   t   tx(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    c         O  s   |  j  j | |   S(   s,   Simple passthrough to SQLAlchemy connectable(   R   Rd   (   R   R6   R  (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRd     s    c   	   	   C  s=   t  | |  d | d | } | j d | d | d | d |  S(   s  Read SQL database table into a DataFrame.

        Parameters
        ----------
        table_name : string
            Name of SQL table in database.
        index_col : string, optional, default: None
            Column to set as index.
        coerce_float : boolean, default True
            Attempts to convert values of non-string, non-numeric objects
            (like decimal.Decimal) to floating point. This can result in
            loss of precision.
        parse_dates : list or dict, default: None
            - List of column names to parse as dates.
            - Dict of ``{column_name: format string}`` where format string is
              strftime compatible in case of parsing string times, or is one of
              (D, s, ns, ms, us) in case of parsing integer timestamps.
            - Dict of ``{column_name: arg}``, where the arg corresponds
              to the keyword arguments of :func:`pandas.to_datetime`.
              Especially useful with databases without native Datetime support,
              such as SQLite.
        columns : list, default: None
            List of column names to select from SQL table.
        schema : string, default None
            Name of SQL schema in database to query (if database flavor
            supports this).  If specified, this overwrites the default
            schema of the SQL database object.
        chunksize : int, default None
            If specified, return an iterator where `chunksize` is the number
            of rows to include in each chunk.

        Returns
        -------
        DataFrame

        See Also
        --------
        pandas.read_sql_table
        SQLDatabase.read_query

        R   Rh   RZ   R9   RY   Rm   (   R   R   (	   R   Rw   R_   RZ   R9   RY   Rh   Rm   Rx   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRv     s    ,c      	   c  sJ   xC t  rE |  j |  } | s" Pq t | | d | d | d | Vq Wd S(   s+   Return generator through chunked result setR_   RZ   R9   N(   R%   R   Ra   (   R   Rm   RY   R_   RZ   R9   R^   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    	c      
   C  s   t  | |  } |  j |   } | j   }	 | d k	 r[ |  j | | |	 d | d | d | S| j   }
 t |
 |	 d | d | d | } | Sd S(   s  Read SQL query into a DataFrame.

        Parameters
        ----------
        sql : string
            SQL query to be executed.
        index_col : string, optional, default: None
            Column name to use as index for the returned DataFrame object.
        coerce_float : boolean, default True
            Attempt to convert values of non-string, non-numeric objects (like
            decimal.Decimal) to floating point, useful for SQL result sets.
        params : list, tuple or dict, optional, default: None
            List of parameters to pass to execute method.  The syntax used
            to pass parameters is database driver dependent. Check your
            database driver documentation for which of the five syntax styles,
            described in PEP 249's paramstyle, is supported.
            Eg. for psycopg2, uses %(name)s so use params={'name' : 'value'}
        parse_dates : list or dict, default: None
            - List of column names to parse as dates.
            - Dict of ``{column_name: format string}`` where format string is
              strftime compatible in case of parsing string times, or is one of
              (D, s, ns, ms, us) in case of parsing integer timestamps.
            - Dict of ``{column_name: arg dict}``, where the arg dict
              corresponds to the keyword arguments of
              :func:`pandas.to_datetime` Especially useful with databases
              without native Datetime support, such as SQLite.
        chunksize : int, default None
            If specified, return an iterator where `chunksize` is the number
            of rows to include in each chunk.

        Returns
        -------
        DataFrame

        See Also
        --------
        read_sql_table : Read SQL database table into a DataFrame.
        read_sql

        R_   RZ   R9   N(   R7   Rd   R1   R#   R   R   Ra   (   R   R4   R_   RZ   R9   R5   Rm   R6   R   RY   R^   R`   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRz     s    *	R   c
           s    r, t     r,   f d   | D   n    d k	 r d d l m }
 m } xM   j   D]< \ } } t |
 |  |  s[ t d j d |    q[ q[ Wn  t	 | |  d | d | d | d	 | d
 | d   } | j
   | j | d |	 | j   r| j   r|  j j } |  j j   + } | j d
 | p>|  j j d |  } Wd QX| | k rd j |  } t j | t  qn  d S(   s  
        Write records stored in a DataFrame to a SQL database.

        Parameters
        ----------
        frame : DataFrame
        name : string
            Name of SQL table.
        if_exists : {'fail', 'replace', 'append'}, default 'fail'
            - fail: If table exists, do nothing.
            - replace: If table exists, drop it, recreate it, and insert data.
            - append: If table exists, insert data. Create if does not exist.
        index : boolean, default True
            Write DataFrame index as a column.
        index_label : string or sequence, default None
            Column label for index column(s). If None is given (default) and
            `index` is True, then the index names are used.
            A sequence should be given if the DataFrame uses MultiIndex.
        schema : string, default None
            Name of SQL schema in database to write to (if database flavor
            supports this). If specified, this overwrites the default
            schema of the SQLDatabase object.
        chunksize : int, default None
            If not None, then rows will be written in batches of this size at a
            time.  If None, all rows will be written at once.
        dtype : single type or dict of column name to SQL type, default None
            Optional specifying the datatype for columns. The SQL type should
            be a SQLAlchemy type. If all columns are of the same type, one
            single value can be used.
        method : {None', 'multi', callable}, default None
            Controls the SQL insertion clause used:

            * None : Uses standard SQL ``INSERT`` clause (one per row).
            * 'multi': Pass multiple values in a single ``INSERT`` clause.
            * callable with signature ``(pd_table, conn, keys, data_iter)``.

            Details and a sample callable implementation can be found in the
            section :ref:`insert method <io.sql.method>`.

            .. versionadded:: 0.24.0
        c           s   i  |  ] }   |  q S(    (    (   t   .0RU   (   RK   (    s,   lib/python2.7/site-packages/pandas/io/sql.pys
   <dictcomp>  s   	 i(   t   to_instancet
   TypeEngines.   The type of {column} is not a SQLAlchemy type t   columnR`   R   R   R   Rh   RK   R   t
   connectionNs   The provided table name '{0}' is not found exactly as such in the database after writing the table, possibly due to case sensitivity issues. Consider using lower case table names.(   R   R#   R  R  R  t   itemsR+   Rt   RH   R   R   R   t   isdigitt   islowerR   R,   t   connectt   table_namesRl   Rh   R  R  R  (   R   R`   Rk   R   R   R   Rh   Rm   RK   R   R  R  RP   t   my_typeRx   R,   R   R  t   msg(    (   RK   s,   lib/python2.7/site-packages/pandas/io/sql.pyR   \  s.    ,
		c         C  s
   |  j  j S(   N(   Rl   t   tables(   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR!    s    c         C  s+   |  j  j |  j  j j | | p' |  j j  S(   N(   R   t   run_callablet   dialectR}   Rl   Rh   (   R   Rk   Rh   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR}     s    	c         C  s   | p |  j  j } | r? |  j  j j d j | | g   } n |  j  j j |  } d d l m } x2 | j D]' } t | j	 |  rn t
 | j	 _ qn qn W| S(   Nt   .i(   t   Numeric(   Rl   Rh   R!  t   gett   joinR$   R%  RY   R+   RL   R*   t	   asdecimal(   R   Rw   Rh   t   tblR%  R  (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    'c         C  sj   | p |  j  j } |  j | |  rf |  j  j d | g d |  |  j | |  j   |  j  j   n  d  S(   NRi   Rh   (   Rl   Rh   R}   Rq   R   t   dropt   clear(   R   Rw   Rh   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s
    c         C  s7   t  | |  d | d t d | d | } t | j    S(   NR`   R   R1   RK   (   R   R*   R   R   (   R   R`   Rw   R1   RK   Rx   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _create_sql_schema  s    	N(   R   R   R  R#   R   R   R   Rd   R%   Rv   t   staticmethodR   Rz   R   R   t   propertyR!  R}   R   R   R,  (    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRu     s*   		/:Kt   TEXTt   stringt   REALRN   R   RO   R   R   t   DATER   t   TIMER   R  c         C  sU   y% t  |   j d d  j d  } Wn) t k
 rP t d j d |     n X| S(   Ns   utf-8t   stricts,   Cannot convert identifier to UTF-8: '{name}'Rk   (   R
   t   encodet   decodet   UnicodeErrorRt   RH   (   Rk   t   uname(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _get_unicode_name  s    %c         C  si   t  |   } t |  s' t d   n  | j d  } | d k rQ t d   n  d | j d d  d S(   Ns$   Empty table or column name specifieds    i    s%   SQLite identifier cannot contain NULst   "s   ""(   R9  R   Rt   t   findR   (   Rk   R8  t	   nul_index(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   _get_valid_sqlite_name  s    sv   The spaces in these column names will not be changed. In pandas versions < 0.14, spaces were converted to underscores.t   SQLiteTablec           B  sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   sw   
    Patch the SQLTable for fallback support.
    Instead of a table variable just use the Create Table statement.
    c         O  s<   d d  l  } | j t d    t t |   j | |   d  S(   Nic         S  s   |  j  d  S(   Ns   %H:%M:%S.%f(   t   strftime(   t   _(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   <lambda>
  s    (   t   sqlite3t   register_adapterR   t   superR>  R   (   R   R6   R  RB  (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    c         C  s   t  d j |  j   S(   Ns   ;
(   R   R'  Rx   (   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    c         C  s=   |  j  j   ( } x |  j D] } | j |  q WWd  QXd  S(   N(   R   R   Rx   Rd   (   R   R   t   stmt(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    c   
      C  s   t  t t |  j j   } d } t } |  j d  k	 rl g  |  j d  d  d  D] } | j d |  ^ qM n  g  | D] } | |  ^ qs } d j	 |  } d j	 | g t
 |   } d j d | |  j  d | d |  }	 |	 S(	   Nt   ?ii    t   ,u.   INSERT INTO {table} ({columns}) VALUES ({wld})Rx   RY   t   wld(   R3   R   R
   R`   RY   R=  R   R#   R   R'  R   RH   Rk   (
   R   R   RH  t   escapeR   R  t   bracketed_namest	   col_namest	   wildcardst   insert_statement(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRM    s    6	c         C  s&   t  |  } | j |  j   |  d  S(   N(   R3   t   executemanyRM  (   R   R   R1   R   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR   %  s    c           s  |  j  |  j  } t j d  } g  | D] \ } } } | ^ q( } t t | j |   rq t j t	 d d n  t
   g  | D]# \ } } }   |  d | ^ q~ } |  j d k	 r0t |  j  r0t |  j  s |  j g }	 n	 |  j }	 d j   f d   |	 D  }
 | j d j d |  j d	 |
   n  d
   |  j  d d j |  d g } g  | D] \ } } } | rb| ^ qb} t |  rd j |  } d j   f d   | D  }
 | j d   d |  j d |  d   |  j  d |
 d  n  | S(   s   
        Return a list of SQL statements that creates a table reflecting the
        structure of a DataFrame.  The first entry will be a CREATE TABLE
        statement while the rest will be CREATE INDEX statements.
        s   \s+R   i   t    s   , c         3  s   |  ] }   |  Vq d  S(   N(    (   R  R   (   RI  (    s,   lib/python2.7/site-packages/pandas/io/sql.pys	   <genexpr>B  s    s-   CONSTRAINT {tbl}_pk PRIMARY KEY ({cnames_br})R)  t	   cnames_brs   CREATE TABLE s    (
s   ,
  s   
)R@  RG  c         3  s   |  ] }   |  Vq d  S(   N(    (   R  R   (   RI  (    s,   lib/python2.7/site-packages/pandas/io/sql.pys	   <genexpr>N  s    s   CREATE INDEX t   ix_s   ON s    (t   )N(   R   t   _sql_type_namet   reR   t   anyR   t   searchR  R  t   _SAFE_NAMES_WARNINGR=  R1   R#   R   R   R'  R   RH   Rk   (   R   R   t   patRU   R@  R   t   cnamet   ctypet   create_tbl_stmtsR1   RP  t   create_stmtsR   t   ix_colst   cnames(    (   RI  s,   lib/python2.7/site-packages/pandas/io/sql.pyR   )  s4    "-		+@c         C  s   |  j  p i  } | j | k r) | | j St j | d t } | d k ri t j d t d d d } nE | d k r~ d } n0 | d	 k r d
 } n | d k r t d   n  | t	 k r d
 } n  t	 | S(   NR   R   sl   the 'timedelta' type is not supported, and will be written as integer values (ns frequency) to the database.R   i   RO   R   R   t   emptyR0  R  s   Complex datatypes not supported(
   RK   Rk   R  R  R%   R  R  R  Rt   t
   _SQL_TYPES(   R   RP   RK   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRS  U  s"    					(
   R   R   R  R   R   R   RM  R   R   RS  (    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR>    s   							,R|   c           B  s   e  Z d  Z e d  Z e d    Z d   Z e d e
 d d   Z d e
 d d d d  Z d   Z d e
 d d d d d d  Z d d	  Z d d
  Z d d  Z d d d  Z RS(   s   
    Version of SQLDatabase to support SQLite connections (fallback without
    SQLAlchemy). This should only be used internally.

    Parameters
    ----------
    con : sqlite connection object

    c         C  s   | |  _  | |  _ d  S(   N(   Rb   R.   (   R   R.   Rb   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR   ~  s    	c         c  s_   |  j  j   } z> y | V|  j  j   Wn! t k
 rK |  j  j     n XWd  | j   Xd  S(   N(   R.   t   cursort   commitR~   t   rollbackt   close(   R   Re   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s     c         O  s   |  j  r |  j } n |  j j   } y. | r@ | j | |   n | j |   | SWn t k
 r } y |  j j   Wn= t k
 r t d j d | d d |   } t |  n Xt d j d | d d |   } t |  n Xd  S(   Ns7   Execution failed on sql: {sql}
{exc}
unable to rollbackR4   i    Rr   s&   Execution failed on sql '{sql}': {exc}(	   Rb   R.   Ra  Rd   R~   Rc  R   RH   R   (   R   R6   R  Re   Rr   t   ex(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRd     s(    			c      	   c  su   xn t  rp |  j |  } t |  t k r9 t |  } n  | sM |  j   Pq t | | d | d | d | Vq Wd S(   s+   Return generator through chunked result setR_   RZ   R9   N(   R%   R   RL   t   tupleR3   Rd  Ra   (   Ra  Rm   RY   R_   RZ   R9   R^   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    	
c      
   C  s   t  | |  } |  j |   } g  | j D] }	 |	 d ^ q( }
 | d  k	 ro |  j | | |
 d | d | d | S|  j |  } | j   t | |
 d | d | d | } | Sd  S(   Ni    R_   RZ   R9   (   R7   Rd   t   descriptionR#   R   t   _fetchall_as_listRd  Ra   (   R   R4   R_   RZ   R5   R9   Rm   R6   Ra  t   col_descRY   R^   R`   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRz     s     
	c         C  s.   | j    } t | t  s* t |  } n  | S(   N(   R   R+   R3   (   R   Re   R   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyRh    s    R   c
           s     r, t     r,   f d   | D   n    d
 k	 r xM   j   D]< \ }
 } t | t  sE t d j d |
 d |    qE qE Wn  t | |  d | d | d | d | d	   } | j   | j	 | |	  d
 S(   si  
        Write records stored in a DataFrame to a SQL database.

        Parameters
        ----------
        frame: DataFrame
        name: string
            Name of SQL table.
        if_exists: {'fail', 'replace', 'append'}, default 'fail'
            fail: If table exists, do nothing.
            replace: If table exists, drop it, recreate it, and insert data.
            append: If table exists, insert data. Create if it does not exist.
        index : boolean, default True
            Write DataFrame index as a column
        index_label : string or sequence, default None
            Column label for index column(s). If None is given (default) and
            `index` is True, then the index names are used.
            A sequence should be given if the DataFrame uses MultiIndex.
        schema : string, default None
            Ignored parameter included for compatibility with SQLAlchemy
            version of ``to_sql``.
        chunksize : int, default None
            If not None, then rows will be written in batches of this
            size at a time. If None, all rows will be written at once.
        dtype : single type or dict of column name to SQL type, default None
            Optional specifying the datatype for columns. The SQL type should
            be a string. If all columns are of the same type, one single value
            can be used.
        method : {None, 'multi', callable}, default None
            Controls the SQL insertion clause used:

            * None : Uses standard SQL ``INSERT`` clause (one per row).
            * 'multi': Pass multiple values in a single ``INSERT`` clause.
            * callable with signature ``(pd_table, conn, keys, data_iter)``.

            Details and a sample callable implementation can be found in the
            section :ref:`insert method <io.sql.method>`.

            .. versionadded:: 0.24.0
        c           s   i  |  ] }   |  q S(    (    (   R  RU   (   RK   (    s,   lib/python2.7/site-packages/pandas/io/sql.pys
   <dictcomp>  s   	 s    {column} ({type!s}) not a stringR  RL   R`   R   R   R   RK   N(
   R   R#   R  R+   R   Rt   RH   R>  R   R   (   R   R`   Rk   R   R   R   Rh   Rm   RK   R   RP   R  Rx   (    (   RK   s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    +	
c         C  s=   d } d j  d |  } t |  j | | g  j    d k S(   NRF  sA   SELECT name FROM sqlite_master WHERE type='table' AND name={wld};RH  i    (   RH   R   Rd   R   (   R   Rk   Rh   RH  t   query(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR}     s    		c         C  s   d  S(   N(   R#   (   R   Rw   Rh   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    c         C  s)   d j  d t |   } |  j |  d  S(   Ns   DROP TABLE {name}Rk   (   RH   R=  Rd   (   R   Rk   Rh   t   drop_sql(    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR     s    	c         C  s7   t  | |  d | d t d | d | } t | j    S(   NR`   R   R1   RK   (   R>  R*   R   R   (   R   R`   Rw   R1   RK   Rx   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR,     s    N(   R   R   R  R*   R   R   R   Rd   R-  R#   R%   R   Rz   Rh  R   R}   R   R   R,  (    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyR|   s  s"   				8c         C  s+   t  d |  } | j |  | d | d | S(   s  
    Get the SQL db table schema for the given frame.

    Parameters
    ----------
    frame : DataFrame
    name : string
        name of SQL table
    keys : string or sequence, default: None
        columns to use a primary key
    con: an open SQL database connection object or a SQLAlchemy connectable
        Using SQLAlchemy makes it possible to use any DB supported by that
        library, default: None
        If a DBAPI2 object, only sqlite3 is supported.
    dtype : dict of column name to SQL type, default None
        Optional specifying the datatype for columns. The SQL type should
        be a SQLAlchemy type, or a string for sqlite3 fallback connection.

    R.   R1   RK   (   Rc   R,  (   R`   Rk   R1   R.   RK   Rf   (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt
   get_schema&  s    (H   R  t
   __future__R    R   t
   contextlibR   R   R   R   t	   functoolsR   RT  R  t   numpyRM   t   pandas._libs.libt   _libsR  t   pandas.compatR   R   R	   R
   R   t   pandas.core.dtypes.commonR   R   R   t   pandas.core.dtypes.dtypesR   t   pandas.core.dtypes.missingR   t   pandas.core.apiR   R   t   pandas.core.baseR   t   pandas.core.tools.datetimesR   R)   R   t   IOErrorR   R#   R"   R0   R7   R:   RQ   RX   R%   Ra   Rd   Ry   R{   R   R   R}   t   table_existsRn   R*   Rc   R   R  Ru   R`  R9  R=  RW  R>  R|   Rl  (    (    (    s,   lib/python2.7/site-packages/pandas/io/sql.pyt   <module>   sv   (					H	<	R	>	  
			u