B
    q\                 @   sn   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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.7/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 }xt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`W t|||d}|rx@t|j D ].\}}tjt	| | d td	}| |_qNW |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"   )r-   r   r"   r"   r#   r/   _   s    r
   r   )dtyper   SOc             S   s   g | ]\}}||iqS r"   r"   )r-   valindexr"   r"   r#   r/   k   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!   ZcolsZkindsr	   r<   r5   ZlettersZjjZkinddataindicesZvalsr   r.   colr?   r"   r"   r#   simple_table8   s6     

rC   c           	   C   sb   ddl m}  ddlm} ddl}|   |d || ddd}W dQ R X | }| }|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.datarD   Zastropy.io.votable.tablerE   warningscatch_warningssimplefilterZget_first_tableZto_table)rD   rE   rG   ZvotableZfirst_tabler   r"   r"   r#   complex_tabley   s    

rJ   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 )ArrayWrapperzC
    Minimal mixin using a simple wrapper around a numpy array
    c             C   s(   t || _dt|ddkr$|j| _d S )Ninfo__dict__r"   )r   r   r@   getattrrL   )r    r@   r"   r"   r#   r$      s    zArrayWrapper.__init__c             C   sB   t |ttjfr| j| }n"| | j| }d| jkr>| j|_|S )NrL   )
isinstanceintr   Zintegerr@   	__class__rM   rL   )r    itemoutr"   r"   r#   __getitem__   s    
zArrayWrapper.__getitem__c             C   s   || j |< d S )N)r@   )r    rR   valuer"   r"   r#   __setitem__   s    zArrayWrapper.__setitem__c             C   s
   t | jS )N)r6   r@   )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)rO   rK   r@   )r    otherr"   r"   r#   __eq__   s    
zArrayWrapper.__eq__c             C   s   | j jS )N)r@   r0   )r    r"   r"   r#   r0      s    zArrayWrapper.dtypec             C   s   | j jS )N)r@   shape)r    r"   r"   r#   rZ      s    zArrayWrapper.shapec             C   s   d | jj| jj| jS )Nz<{0} name='{1}' data={2}>)formatrQ   r%   rL   namer@   )r    r"   r"   r#   __repr__   s    zArrayWrapper.__repr__N)r%   r&   r'   r(   r   rL   r$   rT   rV   rW   rY   propertyr0   rZ   r]   r"   r"   r"   r#   rK      s   	rK   )r   Nr)   F)r(   	itertoolsr   r   Znumpyr   r   r   r   Zastropy.utils.data_infor   r   rC   rJ   rK   r"   r"   r"   r#   <module>   s   '
A