U
    e»{jí  ã                   @   st   d Z ddlZddlZddlmZ ddlmZ ddlZddl	m
Z
 dddgZddd„ZG dd„ de
ƒZedd„ ƒZdS )z7
Table property for providing information about table.
é    N)Úcontextmanager)Úisclass)ÚDataInfoÚ
table_infoÚ	TableInfoÚserialize_method_asÚ
attributesÚ c                 C   sÀ  ddl m} |dkrtj}| jjg}| jr4| d¡ | dt| ƒ› �¡ dd 	|¡ d g}t
| j ¡ ƒ}| jr¨g }|D ]}| |j|d	d
�¡ qx||t
|d ƒd�}	n|ƒ }	|d	krº|	S d|	jkrôdd„ |D ƒ}
t|
ƒdkrôt|d | jƒrô|	d= d|	jk�rt |	d dk¡�r|	d= d|	jk�rDt |	d t| ƒk¡�rD|	d= |	jD ]2}|	| jjdk�rJt |	| dk¡�rJ|	|= �qJ| j�rž| |	jdddd�¡ n
| d¡ | dd„ |D ƒ¡ d	S )a  
    Write summary information about column to the ``out`` filehandle.
    By default this prints to standard output via sys.stdout.

    The ``option`` argument specifies what type of information
    to include.  This can be a string, a function, or a list of
    strings or functions.  Built-in options are:

    - ``attributes``: basic column meta data like ``dtype`` or ``format``
    - ``stats``: basic statistics: minimum, mean, and maximum

    If a function is specified then that function will be called with the
    column as its single argument.  The function must return an OrderedDict
    containing the information attributes.

    If a list is provided then the information attributes will be
    appended for each of the options, in order.

    Examples
    --------
    >>> from astropy.table.table_helpers import simple_table
    >>> t = simple_table(size=2, kinds='if')
    >>> t['a'].unit = 'm'
    >>> t.info()
    <Table length=2>
    name  dtype  unit
    ---- ------- ----
       a   int64    m
       b float64

    >>> t.info('stats')
    <Table length=2>
    name mean std min max
    ---- ---- --- --- ---
       a  1.5 0.5   1   2
       b  1.5 0.5   1   2

    Parameters
    ----------
    option : str, callable, list of (str or callable)
        Info option, defaults to 'attributes'.
    out : file-like, None
        Output destination, default is sys.stdout.  If None then a
        Table with information attributes is returned

    Returns
    -------
    info : `~astropy.table.Table` if out==None else None
    é   )ÚTabler	   zmasked=Truezlength=ú<ú ú>N)Úoutr   )ÚnamesÚclassc                 S   s   h | ]}t |ƒ’qS © )Útype)Ú.0Úcolr   r   úQ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/table/info.pyÚ	<setcomp>b   s     ztable_info.<locals>.<setcomp>Zn_badÚlengthZSUéÿÿÿÿF)Ú	max_widthÚ	max_linesZ	show_unitz<No columns>c                 s   s   | ]}|t j V  qd S ©N)ÚosÚlinesep)r   Úoutliner   r   r   Ú	<genexpr>v   s     ztable_info.<locals>.<genexpr>)Útabler   ÚsysÚstdoutÚ	__class__Ú__name__ZmaskedÚappendÚlenÚjoinÚlistÚcolumnsÚvaluesZcolnamesÚinfoÚ
isinstanceZColumnClassÚnpÚallZdtypeÚkindÚextendÚpformatÚ
writelines)ÚtblÚoptionr   r   Z
descr_valsZoutlinesÚcolsÚinfosr   r,   Z
uniq_typesÚnamer   r   r   r      s@    2


 $
&

c                   @   s   e Zd Zddd„Zeje_dS )r   r   r	   c                 C   s   t | j||ƒS r   )r   Z_parent)Úselfr5   r   r   r   r   Ú__call__z   s    zTableInfo.__call__N)r   r	   )r%   Ú
__module__Ú__qualname__r:   r   Ú__doc__r   r   r   r   r   y   s   
c              
   #   s˜   ‡fdd„}i }ˆrd|   ¡ D ]F}t|jdƒr||ƒ‰ ˆ r|jj||jj< ‡ fdd„|jjD ƒ|j_qz
dV  W 5 ˆr’| ¡ D ]\}}|| | j_q|X dS )aÛ  Context manager to temporarily override individual
    column info.serialize_method dict values.  The serialize_method
    attribute is an optional dict which might look like ``{'fits':
    'jd1_jd2', 'ecsv': 'formatted_value', ..}``.

    ``serialize_method`` is a str or dict.  If str then it the the value
    is the ``serialize_method`` that will be used for all formats.
    If dict then the key values can be either:

    - Column name.  This has higher precedence than the second option of
      matching class.
    - Class (matches any column which is an instance of the class)

    This context manager is expected to be used only within ``Table.write``.
    It could have been a private method on Table but prefer not to add
    clutter to that class.

    Parameters
    ----------
    tbl : Table object
        Input table
    serialize_method : dict, str
        Dict with key values of column names or types, or str

    Returns
    -------
    None (context manager)
    c                    sR   t ˆ tƒrˆ S | jjˆ kr&ˆ | jj S ˆ D ]"}t|ƒr*t | |ƒr*ˆ |   S q*dS )zÂ
        Determine if the ``serialize_method`` str or dict specifies an
        override of column presets for ``col``.  Returns the matching
        serialize_method value or ``None``.
        N)r-   Ústrr,   r8   r   )r   Úkey)Úserialize_methodr   r   Úget_override_smŸ   s    
z,serialize_method_as.<locals>.get_override_smr@   c                    s   i | ]
}|ˆ “qS r   r   )r   Úfmt)Úoverride_smr   r   Ú
<dictcomp>Í   s     z'serialize_method_as.<locals>.<dictcomp>N)ZitercolsÚhasattrr,   r@   r8   Úitems)r4   r@   rA   Zoriginal_smsr   r8   Zoriginal_smr   )rC   r@   r   r   €   s     
ÿ
)r   r	   )r=   r   r"   Ú
contextlibr   Úinspectr   Únumpyr.   Zastropy.utils.data_infor   Ú__all__r   r   r   r   r   r   r   Ú<module>   s   

g