
    IR-e                         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          ZddZd Z G d de          Z G d d          ZdS )zT
Helper functions for table development, mostly creating useful
tables for testing.
    N)cycle)ParentDtypeInfo   )ColumnTablec                       e Zd ZdZ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                 j   || _         t          | j                   | _        t          j                            d           t          j        |          | j        d<   t          j                            |          | j        d<   t          j                            |          dk    | j        d<   t          j                            |df          | j        d<   t          j                            t          j        t          t          j                            |          | j        d	<   d
dt          j        dd          dd| _        t          j                            dd|          | _        t          j        | j        d         dk              d         | _        | j                            d	          | _        t          | j                   | _        t          j        d|d          | j        d<   t          j                                        | j        d<   | j                            d           t          | j                   | _        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repeat	extra_rowrandintextra_columnwhererow_indicesgroup_bytable_groupedother_tablesortother_table_2	bool_mask)selfsizer   s      ;lib/python3.11/site-packages/astropy/table/table_helpers.py__init__zTimingTables.__init__   s    $+...
 		u)D//
3)**400
3)**40036
3)**D":66
3)**28D9M4N4N+O+OQUVV
3"BIa4D4D3OOI--ad;;8DJsOc$9::1=!Z0055 !444 "	!T1 5 5 "	 0 0 2 2c""" #$+666"$)"2"24"8"83"$)"2"2D":">">3C3.    N)r
   F)__name__
__module____qualname____doc__r2    r3   r1   r	   r	      s2         
/ / / / / /r3   r	   r   ifSFc                 P   |t          |          }|dk    rt          d          g }d t          |          D             }t          j        d t
          j        D                       }t          t          |          t          |                    D ]\  }}|dk    r(t          j	        d| dz   t          j
                  |z   }	n|d	k    r$t          j	        | t          j                  |z   }	n|d
k    r0t          j	        |           |z   t          |          z  }
||
         }	n_|dk    rJt          j	        |           |z   t          |          z  }
||
         }d t          ||
          D             }	nt          d          |                    t          |	                     t          |||          }|rgt          |j                                                  D ]@\  }}t          j        t          j	        |           |z   dz  t$                    }| |_        A|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                 L    g | ]!}t          t          d           |z             "S )r   )chrord).0iis     r1   
<listcomp>z simple_table.<locals>.<listcomp>`   s*    666BSSB666r3   c                     g | ]}|S r8   r8   )r?   r   s     r1   rA   z simple_table.<locals>.<listcomp>a   s    888a888r3   r   r   )dtyper   SOc                     g | ]	\  }}||i
S r8   r8   )r?   valindexs      r1   rA   z simple_table.<locals>.<listcomp>m   s     FFFZS%S%LFFFr3   zUnknown data kind)namesr   r   )len
ValueErrorranger   r   r!   r"   zipr   r   int64float64appendr   r   	enumeratecolumnsvaluesboolmask)r0   colskindsr   rR   rI   lettersjjkinddataindicesvalsr   r@   colrU   s                   r1   simple_tabler_   :   s   @ |5zzbyy8999G66%++666Eh886#788899GdU5\\22 % %D3;;9Qq999B>DDS[[9T444r9DDS[[y+s7||;G7#DDS[[y+s7||;G7#DFF3tW3E3EFFFDD0111vd||$$$$'v666E  !5!5!7!788 	 	GB8RYt__r1Q6dCCCDuCHHLr3   c                  $   ddl } ddlm} ddlm} |                                 5  |                     d            | |d          d          }ddd           n# 1 swxY w Y   |                                }|                                }|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)pedantic)	warningsastropy.io.votable.tablera   astropy.utils.datarb   catch_warningssimplefilterget_first_tableto_table)re   ra   rb   votablefirst_tabler   s         r1   complex_tablern   {   s    
 OOO......888888		 	 	"	" 
 
h'''%!!"KLL
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ))++K  ""ELs   ,AA!$A!c                       e Zd ZdZd Zd ZdS )ArrayWrapperInfor[   c                 &    | j         }d|j        i}|S )z2Represent Column as a dict that can be serialized.r[   )_parentr[   )r/   r^   outs      r1   _represent_as_dictz#ArrayWrapperInfo._represent_as_dict   s    lsx 
r3   c                 L    |                     d          } | j        |fi |}|S )zConstruct Column from ``map``.r[   )pop_parent_cls)r/   mapr[   rs   s       r1   _construct_from_dictz%ArrayWrapperInfo._construct_from_dict   s0    wwvdt++s++
r3   N)r4   r5   r6   _represent_as_dict_primary_datart   ry   r8   r3   r1   rp   rp      s8        &,#      r3   rp   c                   x    e Zd ZdZ e            ZddZd Zd Zd Z	d Z
ed             Zed	             Z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                 ~    t          j        ||          | _        dt          |dd          v r|j        | _        d S d S )Ncopyinfo__dict__r8   )r   r   r[   getattrr   )r/   r[   r   s      r1   r2   zArrayWrapper.__init__   sD    HT---	WT:r2222	DIII 32r3   c                     t          |t          t          j        f          r| j        |         }n7|                     | j        |         d          }d| j        v r| j        |_        |S )NFr~   r   )
isinstanceintr   integerr[   	__class__r   r   )r/   itemrs   s      r1   __getitem__zArrayWrapper.__getitem__   s^    dS"*-.. 	%)D/CC..4u.==C&&9
r3   c                     || j         |<   d S N)r[   )r/   r   values      r1   __setitem__zArrayWrapper.__setitem__   s    	$r3   c                 *    t          | j                  S r   )rJ   r[   r/   s    r1   __len__zArrayWrapper.__len__   s    49~~r3   c                 b    t          |t                    r| j        |j        k    S | j        |k    S )z6Minimal equality testing, mostly for mixin unit tests.)r   r|   r[   )r/   others     r1   __eq__zArrayWrapper.__eq__   s0    e\** 	&9
**9%%r3   c                     | j         j        S r   )r[   rC   r   s    r1   rC   zArrayWrapper.dtype       yr3   c                     | j         j        S r   )r[   shaper   s    r1   r   zArrayWrapper.shape   r   r3   c                 L    d| j         j         d| j        j         d| j         dS )N<z name='z' data=>)r   r4   r   namer[   r   s    r1   __repr__zArrayWrapper.__repr__   s.    V4>*VV49>VV$)VVVVr3   N)T)r4   r5   r6   r7   rp   r   r2   r   r   r   r   propertyrC   r   r   r8   r3   r1   r|   r|      s          D" " " "
         & & &   X   XW W W W Wr3   r|   )r   Nr9   F)r7   r!   	itertoolsr   numpyr   astropy.utils.data_infor   r   r   r   r	   r_   rn   rp   r|   r8   r3   r1   <module>r      s               3 3 3 3 3 3                $/ $/ $/ $/ $/ $/ $/ $/N> > > >B  ,        1W 1W 1W 1W 1W 1W 1W 1W 1W 1Wr3   