
    IR-e                         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	Z G d
 de
          Zed             ZdS )z7
Table property for providing information about table.
    N)contextmanager)isclass)DataInfo)
table_info	TableInfoserialize_method_as
attributes c                    ddl m} |dk    rt          j        }| j        j        g}| j        r|                    d           |                    dt          |                       dd	                    |          z   dz   g}t          | j                                                  }| j        rRg }|D ],}|                    |                    |d	
                     - ||t          |d                             }	n
 |            }	||	S d|	j        v r=d |D             }
t          |
          dk    rt          |d         | j                  r|	d= d|	j        v r!t#          j        |	d         dk              r|	d= d|	j        v r.t#          j        |	d         t          |           k              r|	d= |	j        D ]7}|	|         j        j        dv r!t#          j        |	|         dk              r|	|= 8| j        r,|                    |	                    ddd                     n|                    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                 ,    h | ]}t          |          S  )type).0cols     2lib/python3.11/site-packages/astropy/table/info.py	<setcomp>ztable_info.<locals>.<setcomp>b   s    000Cd3ii000    n_badlengthSUF)	max_width	max_lines	show_unitz<No columns>c              3   4   K   | ]}|t           j        z   V  d S N)oslinesep)r   outlines     r   	<genexpr>ztable_info.<locals>.<genexpr>v   s)      @@G7RZ'@@@@@@r   )tabler   sysstdout	__class____name__maskedappendlenjoinlistcolumnsvaluescolnamesinfo
isinstanceColumnClassnpalldtypekindextendpformat
writelines)tbloptionr   r   
descr_valsoutlinescolsinfosr   r6   
uniq_typesnames               r   r   r      s   d 
byyj-()J
z )-(((*C**+++chhz***S01H""$$%%D
|  	5 	5CLL&d334444uU$uQx..111uww
{ $- 104000
z??aJtAw$H$HW$-BF4=A+=$>$>M 4=  RVDNc#hh,F%G%G N  : D((RVDJ"4D-E-E(T

| (rR5QQRRRR'''NN@@x@@@@@@@@r   c                   .    e Zd ZddZej        e_        dS )r   r	   r
   c                 .    t          | j        ||          S r$   )r   _parent)selfrA   r   s      r   __call__zTableInfo.__call__z   s    $,444r   Nr	   r
   )r-   
__module____qualname__rL   r   __doc__r   r   r   r   r   y   s1        5 5 5 5 ")Hr   r   c              #     K   fd}i }rt|                                  D ]_}t          |j        d          rH ||          r;|j        j        ||j        j        <   fd|j        j        D             |j        _        `	 dV  r,|                                D ]\  }}|| |         j        _        dS dS # r,|                                D ]\  }}|| |         j        _        w w xY w)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                     t          t                    rS | j        j        v r| j        j                 S D ]+}t	          |          rt          | |          r
|         c S ,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)r7   strr6   rG   r   )r   keyserialize_methods     r   get_override_smz,serialize_method_as.<locals>.get_override_sm   s     &,, 	$## 8=,,,#CHM22 $ 	- 	-Cs|| -
3 4 4 -',,,,tr   rU   c                     i | ]}|S r   r   )r   fmtoverride_sms     r   
<dictcomp>z'serialize_method_as.<locals>.<dictcomp>   s(     1 1 1-0[1 1 1r   N)itercolshasattrr6   rU   rG   items)r@   rU   rV   original_smsr   rG   original_smrY   s    `     @r   r   r      sc     >    6 L  <<>> 	 	Csx!344 -oc22  36(2KL/1 1 1 147H4M1 1 1CH-
>  	>%1%7%7%9%9 > >!k2=D	//	> 	>> >  	>%1%7%7%9%9 > >!k2=D	//	>>s   B9 91C*rM   )rP   r%   r*   
contextlibr   inspectr   numpyr9   astropy.utils.data_infor   __all__r   r   r   r   r   r   <module>re      s     
			 


 % % % % % %           , , , , , ,
<
<
<dA dA dA dAN* * * * * * * * X> X> X> X> X>r   