U
    e»{jà  ã                   @   s~   d Z ddlZddlmZ ddlZddlmZ ddlm	Z	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.
é    N)Úcycle)ÚParentDtypeInfoé   )ÚColumnÚTablec                   @   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ÚnpÚrandomÚseedÚarangeÚchoiceÚarrayÚlistÚstringÚascii_lettersÚrepeatZ	extra_rowÚrandintZextra_columnÚwhereZrow_indicesZgroup_byZtable_groupedZother_tableÚsortZother_table_2Z	bool_mask)ÚselfÚsizer	   © r&   úZ/var/www/html/bwave/python/venv/lib/python3.8/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krt |ƒ}|dkr tdƒ‚g }dd„ t|ƒD ƒ}t dd„ tjD ƒ¡}tt|ƒt|ƒƒD ]Æ\}}|dkrŠtj	d| d tj
d	�| }	nŒ|d
kr¨tj	| tjd	�| }	nn|dkrÐt 	| ¡| 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>`   s     z simple_table.<locals>.<listcomp>c                 S   s   g | ]}|‘qS r&   r&   )r1   r   r&   r&   r'   r3   a   s     r
   r   )Údtyper   ÚSÚOc                 S   s   g | ]\}}||i‘qS r&   r&   )r1   ÚvalÚindexr&   r&   r'   r3   m   s     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%   ÚcolsÚkindsr	   r@   r9   ÚlettersZjjÚkindÚdataÚindicesÚvalsr   r2   ÚcolrC   r&   r&   r'   Úsimple_table:   s6     

rL   c               	   C   sb   ddl } ddlm} ddlm} |  ¡ �  |  d¡ ||dƒdd�}W 5 Q R X | ¡ }| ¡ }|S )	zl
    Return a masked table from the io.votable test set that has a wide variety
    of stressing types.
    r   N)Úparse)Úget_pkg_data_filenameÚignorez'../io/votable/tests/data/regression.xmlF)Zpedantic)	ÚwarningsZastropy.io.votable.tablerM   Zastropy.utils.datarN   Úcatch_warningsÚsimplefilterZget_first_tableZto_table)rP   rM   rN   ZvotableZfirst_tabler   r&   r&   r'   Úcomplex_table{   s    

þrS   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚArrayWrapperInforH   c                 C   s   | j }d|ji}|S )z2Represent Column as a dict that can be serialized.rH   )Z_parentrH   )r$   rK   Úoutr&   r&   r'   Ú_represent_as_dict”   s    
z#ArrayWrapperInfo._represent_as_dictc                 C   s   |  d¡}| j|f|Ž}|S )zConstruct Column from ``map``.rH   )ÚpopZ_parent_cls)r$   ÚmaprH   rU   r&   r&   r'   Ú_construct_from_dictš   s    
z%ArrayWrapperInfo._construct_from_dictN)r)   r*   r+   Z_represent_as_dict_primary_datarV   rY   r&   r&   r&   r'   rT   ‘   s   rT   c                   @   s`   e Zd ZdZeƒ Zd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.
    Tc                 C   s,   t j||d�| _dt|ddƒkr(|j| _d S )N©ÚcopyÚinfoÚ__dict__r&   )r   r   rH   Úgetattrr]   )r$   rH   r\   r&   r&   r'   r(   ®   s    zArrayWrapper.__init__c                 C   sF   t |ttjfƒr| j| }n&| j| j| dd�}d| jkrB| j|_|S )NFr[   r]   )Ú
isinstanceÚintr   ÚintegerrH   Ú	__class__r^   r]   )r$   ÚitemrU   r&   r&   r'   Ú__getitem__³   s    
zArrayWrapper.__getitem__c                 C   s   || j |< d S ©N)rH   )r$   rd   Úvaluer&   r&   r'   Ú__setitem__¼   s    zArrayWrapper.__setitem__c                 C   s
   t | jƒS rf   )r:   rH   ©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)r`   rZ   rH   )r$   Úotherr&   r&   r'   Ú__eq__Â   s    
zArrayWrapper.__eq__c                 C   s   | j jS rf   )rH   r4   ri   r&   r&   r'   r4   É   s    zArrayWrapper.dtypec                 C   s   | j jS rf   )rH   Úshaperi   r&   r&   r'   rm   Í   s    zArrayWrapper.shapec                 C   s"   d| j j› d| jj› d| j› d�S )Nú<z name='z' data=ú>)rc   r)   r]   ÚnamerH   ri   r&   r&   r'   Ú__repr__Ñ   s    zArrayWrapper.__repr__N)T)r)   r*   r+   r,   rT   r]   r(   re   rh   rj   rl   Úpropertyr4   rm   rq   r&   r&   r&   r'   rZ   ¡   s   

	

rZ   )r   Nr-   F)r,   r   Ú	itertoolsr   Únumpyr   Zastropy.utils.data_infor   r   r   r   r   rL   rS   rT   rZ   r&   r&   r&   r'   Ú<module>   s   '
A