B
    T\	                 @   s0   d dl mZ d dlZd dlZdd Zdd ZdS )    )absolute_importNc       
      C   s   | j dk	od| j k}|rFt| j d d}dd |dg D }ni }i }xFtt| D ]6}| | }|j|kr~||j }n
|j	 }|||j< q\W |rx|D ]}	d||	< qW |S )z4Convert a pyarrow.Schema object to pandas dtype dictNs   pandasutf8c          
   S   s&   i | ]}|d  | d| ddqS )Z
numpy_typeZ
field_namenameN)get).0c r   6lib/python3.7/site-packages/dask/dataframe/io/utils.py
<dictcomp>   s   z'_get_pyarrow_dtypes.<locals>.<dictcomp>columnscategory)
Zmetadatajsonloadsdecoder   rangelenr   typeZto_pandas_dtype)
ZschemaZ
categoriesZhas_pandas_metadataZpandas_metadataZpandas_metadata_dtypesZdtypesiZfieldZnumpy_dtypecatr   r   r	   _get_pyarrow_dtypes   s"    


r   c             C   s   t jdd | D | d}|t|  }|s0|S t|ts@|g}||}t|dkrj|d dkrjd|j_t|dkr|d |j	_n||j	_
|S )aN  Get the final metadata for the dask.dataframe

    Parameters
    ----------
    to_read_columns : list
        All the columns to end up with, including index names
    file_dtypes : dict
        Mapping from column name to dtype for every element
        of ``to_read_columns``
    index_cols : list
        Subset of ``to_read_columns`` that should move to the
        index
    column_index_names : list
        The values for df.columns.name for a MultiIndex in the
        columns, or df.index.name for a regular Index in the columns

    Returns
    -------
    meta : DataFrame
    c             S   s    i | ]\}}t jg |d |qS ))Zdtype)pdZSeries)r   r   dr   r   r	   r
   ;   s   z%_meta_from_dtypes.<locals>.<dictcomp>)r      r   Z__index_level_0__N)r   Z	DataFrameitemslist
isinstanceZ	set_indexr   indexr   r   names)Zto_read_columnsZfile_dtypesZ
index_colsZcolumn_index_namesmetaZdfr   r   r	   _meta_from_dtypes%   s    



r   )Z
__future__r   Zpandasr   r   r   r   r   r   r   r	   <module>   s   