a
    ߙfb                     @   s~   d Z ddlmZ ddlZddlZddlmZmZ ddl	m
Z
 G dd dZdddZdd ZG dd de
ZG dd dZdS )zT
Helper functions for table development, mostly creating useful
tables for testing.
    )cycleN   )TableColumn)ParentDtypeInfoc                   @   s   e Zd ZdZdddZdS )TimingTablesz{
    Object which contains two tables and various other attributes that
    are useful for timing and other API tests.
      Fc                 C   sh  || _ t| j d| _tjd t|| jd< tj|| jd< tj|dk| jd< tj|df| jd< tjtt	t
j|| jd	< d
dtdddd| _tjdd|| _t| jd dkd | _| jd	| _t| j d| _td|d| jd< tj | jd< | jd t| j d| _tj|| jd< tj|df| jd< | jd dk| _d S )N)maskedi90  iag      ?b
   cdg333333?Tr   Z)r   r   r   r   r   d   g?   fghg333333?)r	   r   tablenpZrandomZseedarangeZchoicearrayliststringascii_lettersrepeatZ	extra_rowZrandintZextra_columnwhereZrow_indicesZgroup_byZtable_groupedZother_tablesortZother_table_2Z	bool_mask)selfsizer	    r"   :lib/python3.9/site-packages/astropy/table/table_helpers.py__init__   s(     zTimingTables.__init__N)r   F)__name__
__module____qualname____doc__r$   r"   r"   r"   r#   r      s   r   r   ifSFc                 C   s|  |du rt |}|dkr tdg }dd t|D }tdd tjD }tt|t|D ]\}}|dkrtj	d| d tj
d	| }	n|d
krtj	| tjd	| }	nn|dkrt	| | t | }
||
 }	nF|dkrt	| | t | }
||
 }dd t||
D }	ntd|t|	 q^t|||d}|rxt|j D ].\}}tjt	| | d td	}| |_qH|S )a<  
    Return a simple table for testing.

    Example
    --------
    ::

      >>> from astropy.table.table_helpers import simple_table
      >>> print(simple_table(3, 6, masked=True, kinds='ifOS'))
       a   b     c      d   e   f
      --- --- -------- --- --- ---
       -- 1.0 {'c': 2}  --   5 5.0
        2 2.0       --   e   6  --
        3  -- {'e': 4}   f  -- 7.0

    Parameters
    ----------
    size : int
        Number of table rows
    cols : int, optional
        Number of table columns. Defaults to number of kinds.
    kinds : str
        String consisting of the column dtype.kinds.  This string
        will be cycled through to generate the column dtype.
        The allowed values are 'i', 'f', 'S', 'O'.

    Returns
    -------
    out : `Table`
        New table with appropriate characteristics
    N   zMax 26 columns in SimpleTablec                 S   s   g | ]}t td | qS )r   )chrord).0iir"   r"   r#   
<listcomp>^       z simple_table.<locals>.<listcomp>c                 S   s   g | ]}|qS r"   r"   )r-   r   r"   r"   r#   r/   _   r0   r
   r   )dtyper   SOc                 S   s   g | ]\}}||iqS r"   r"   )r-   valindexr"   r"   r#   r/   k   r0   zUnknown data kind)namesr	   r   )len
ValueErrorranger   r   r   r   zipr   r   Zint64Zfloat64appendr   r   	enumeratecolumnsvaluesboolmask)r!   ZcolsZkindsr	   r=   r6   ZlettersZjjkinddataindicesZvalsr   r.   colr@   r"   r"   r#   simple_table8   s6     

rE   c                  C   sv   ddl m}  ddlm} ddl}| * |d || ddd}W d   n1 sX0    Y  | }| }|S )	zl
    Return a masked table from the io.votable test set that has a wide variety
    of stressing types.
    r   )get_pkg_data_filename)parseNignorez'../io/votable/tests/data/regression.xmlF)Zpedantic)	Zastropy.utils.datarF   Zastropy.io.votable.tablerG   warningscatch_warningssimplefilterZget_first_tableZto_table)rF   rG   rI   ZvotableZfirst_tabler   r"   r"   r#   complex_tabley   s    

$rL   c                   @   s    e Zd ZdZdd Zdd ZdS )ArrayWrapperInforB   c                 C   s   | j }d|ji}|S )z2Represent Column as a dict that can be serialized.rB   )Z_parentrB   )r    rD   outr"   r"   r#   _represent_as_dict   s    
z#ArrayWrapperInfo._represent_as_dictc                 C   s    | d}| j|fi |}|S )zConstruct Column from ``map``.rB   )popZ_parent_cls)r    maprB   rN   r"   r"   r#   _construct_from_dict   s    
z%ArrayWrapperInfo._construct_from_dictN)r%   r&   r'   Z_represent_as_dict_primary_datarO   rR   r"   r"   r"   r#   rM      s   rM   c                   @   s^   e Zd ZdZe Zdd Zdd Zdd Zdd	 Z	d
d Z
edd Zedd Zdd ZdS )ArrayWrappera  
    Minimal mixin using a simple wrapper around a numpy array

    TODO: think about the future of this class as it is mostly for demonstration
    purposes (of the mixin protocol). Consider taking it out of core and putting
    it into a tutorial. One advantage of having this in core is that it is
    getting tested in the mixin testing though it doesn't work for multidim
    data.
    c                 C   s(   t || _dt|ddv r$|j| _d S )Ninfo__dict__r"   )r   r   rB   getattrrT   )r    rB   r"   r"   r#   r$      s    zArrayWrapper.__init__c                 C   sB   t |ttjfr| j| }n"| | j| }d| jv r>| j|_|S )NrT   )
isinstanceintr   ZintegerrB   	__class__rU   rT   )r    itemrN   r"   r"   r#   __getitem__   s    
zArrayWrapper.__getitem__c                 C   s   || j |< d S N)rB   )r    rZ   valuer"   r"   r#   __setitem__   s    zArrayWrapper.__setitem__c                 C   s
   t | jS r\   )r7   rB   r    r"   r"   r#   __len__   s    zArrayWrapper.__len__c                 C   s$   t |tr| j|jkS | j|kS dS )z5Minimal equality testing, mostly for mixin unit testsN)rW   rS   rB   )r    otherr"   r"   r#   __eq__   s    
zArrayWrapper.__eq__c                 C   s   | j jS r\   )rB   r1   r_   r"   r"   r#   r1      s    zArrayWrapper.dtypec                 C   s   | j jS r\   )rB   shaper_   r"   r"   r#   rc      s    zArrayWrapper.shapec                 C   s"   d| j j d| jj d| j dS )N<z name='z' data=>)rY   r%   rT   namerB   r_   r"   r"   r#   __repr__   s    zArrayWrapper.__repr__N)r%   r&   r'   r(   rM   rT   r$   r[   r^   r`   rb   propertyr1   rc   rg   r"   r"   r"   r#   rS      s   		

rS   )r   Nr)   F)r(   	itertoolsr   r   Znumpyr   r   r   r   Zastropy.utils.data_infor   r   rE   rL   rM   rS   r"   r"   r"   r#   <module>   s   '
A