a
    ߙfb                     @   sr   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
 g d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rg }|D ]}||j|d	d
 qx||t
|d d}	n| }	|d	u r|	S d|	jv rtdd |D }
t|
dkrt|d | jr|	d= d|	jv rt|	d dkr|	d= d|	jv rHt|	d t| krH|	d= |	jD ]2}|	| jjdv rNt|	| dkrN|	|= qN| 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   | ]}t |V  qd S N)type).0col r   1lib/python3.9/site-packages/astropy/table/info.py	<genexpr>`       ztable_info.<locals>.<genexpr>Zn_badZlengthZSUF)Z	max_widthZ	max_linesZ	show_unitz<No columns>c                 s   s   | ]}|t j V  qd S r   )oslinesep)r   Zoutliner   r   r   r   t   r   )tabler   sysstdout	__class____name__ZmaskedappendlenjoinlistcolumnsvaluesZcolnamesinfoset
isinstanceZColumnClassnpallZdtypekindextendZpformat
writelines)tbloptionr   r   Z
descr_valsZoutlinesZcolsZinfosr   r(   Z
uniq_typesnamer   r   r   r      s@    2


 $
&

r   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)selfr1   r   r   r   r   __call__x   s    zTableInfo.__call__N)r   r	   )r!   
__module____qualname__r4   r   __doc__r   r   r   r   r   w   s   
r   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 r| D ]\}}|| | j_qzn$r| D ]\}}|| | j_q0 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 v 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(   r2   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   Zfmt)override_smr   r   
<dictcomp>   s   z'serialize_method_as.<locals>.<dictcomp>N)Zitercolshasattrr(   r:   r2   items)r0   r:   r;   Zoriginal_smsr   r2   Zoriginal_smr   )r<   r:   r   r   ~   s&    
r   )r   r	   )r7   r   r   
contextlibr   inspectr   Znumpyr+   Zastropy.utils.data_infor   __all__r   r   r   r   r   r   r   <module>   s   
g