
    IR-e/                         d dl Z d dlmZ d dlmZ d dlmZ d dlZd dl	Z	d dl
mZmZmZ d dl
mZ d dlmZ d dlmZ d d	lmZmZ d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"dS )    N)OrderedDict)deepcopy)StringIO)coordinatestabletime)units)serialize_method_as)simple_table)data_info_factorydtype_info_namec           	         t          j        g dd          }t          j        g dd          }t          j        g dd          }|                     |||gg d          }|                    d	
          }| j        j        dk    rdgng }|j        g dk    sJ t          j        |d         g dk              sJ t          j        |d         ddt          d          gk              sJ |r$t          j        |d         dgdz  k              sJ g dt          j	        z  |d<   d|d         _
        d|d         _        t          j        g dd          |d<   d|d         j        _
        t          j        g dg dd          |d<   d|d         j        _
        |                    d	
          }t          j        |d         d                                k              sJ t          j        |d         ddt          d          d d!d!gk              sJ t          j        |d"         g d#k              sJ t          j        |d$         g d%k              sJ t          j        |d&         g d'k              sJ |j        j        }t          j        |d         ||||d(d)gk              sJ t%                      }|                    |
           t'          |j                  |                                k    sJ d	S )*zQ
    Test the info() method of printing a summary of table column attributes
             int32dtypefloat32)ace|S1)r   br   namesNoutMyTableclass)	namer   shapeunitformatdescriptionr!   n_badlengthr"   r   S1MyColumnr   dquantity%02dr   mjdr%   r   r   degr$   fskycoordza b c d e ffloat64objectr$   ) r6   r6   mr6   zdeg,degr%   )r-   r6   r6   r6   r6   r6   r&   )r6   r6   r6   r,   r   r3   TimeSkyCoord)nparrayTableinfo__name__colnamesallr   ur7   r&   r%   r   r8   r   r9   splitColumnClassr   reprgetvalue)	table_typesr   r   r   ttinfosubclsclsr   s	            =lib/python3.11/site-packages/astropy/table/tests/test_info.pytest_table_info_attributesrL      s=    	'***A
),,,A
...A1a)???;;A FFtFE%+4	AAgYYrF> 
 
 
 
 
 
 
 6%-???2333336%.Wi9N9N$OOPPPPP :veGnq(8899999 YY_AcF#AcFAcFMYyyy///AcF$AcFK!)))YYYUCCCAcF(AcFKFFtFE6%-=#6#6#8#88999996gY 5 5y(HU	V     6%-#C#C#CCDDDDD6%/%A%A%AABBBBB6%&*V*V*VVWWWWW
-
 C6%.S#sC$LLMMMMM **CFFsFOOO<<3<<>>))))))    c                    t          j        g dd          }t          j        g dd          }t          j        g dd          }t          j        g ddd	          }|                     ||||gg d
          }|j        rdnd}t                      }|                    d|           d|j        j	         d| d}|ddddddg}	|
                                                                |	k    sJ |                    ddgd          }
|
j        g dk    sJ t          j        |
d         g dk              sJ t          j        |
d         g dk              sJ t          j        |
d          g d!k              sJ t          j        |
d"         g d#k              sJ t                      }|                    d|           |ddddddg}	|
                                                                |	k    sJ t          d$d%gt           j        d& g'          }t                      }|                    d|gd          }
|
j        g d(k    sJ t          j        |
d)         g d
k              sJ t          j        |
d*         ddt!          d+          d,gk              sJ t          j        |
d$         g d-k              sJ t          j        |
d%         g d.k              sJ dS )/zQ
    Test the info() method of printing a summary of table column statistics
    )r   r   r   r   r   r   r   )r   r   r   r2   r   r.   tai)r%   scale)r   r   r   r+   r   zmasked=True r6   statsr   < z	length=4>zname mean std min maxz---- ---- --- --- ---z   a  1.5 0.5   1   2z   b  1.5 0.5   1   2z   c   --  --  --  --z   d  1.5  -- 1.0 2.0
attributesN)r"   r   r#   r$   r%   r&   r!   meanstdminmaxr'   r(   rU   )1.5rY   --rY   rV   )0.5r[   rZ   rZ   rW   )1r\   rZ   1.0rX   )2r^   rZ   z2.0sumfirstc                     | d         S )Nr    )cols    rK   <lambda>z'test_table_info_stats.<locals>.<lambda>   s
    3q6 rM   )r   funcs)r"   r   r#   r$   r%   r&   r!   r_   r`   r'   r(   r"   r   r)   r5   )6rf   rZ   rZ   )r\   r\   r   r]   )r:   r;   r   r8   r<   maskedr   r=   	__class__r>   rE   
splitlinesr?   r@   r   r_   r   )rF   r   r   r   r+   rG   rg   r   table_header_lineexprH   customs               rK   test_table_info_statsrm   J   s    	W---A
Y///A
%%%U333A	,,,uE:::A1aA,.B.B.BCCA  !x/^^RF
**CFF7FDAK0DD6DDDC <<>>$$&&#---- FFL'*F55E>        6%-#>#>#>>?????6%,"<"<"<<=====6%,"9"9"99:::::6%,"9"9"99:::::
**CFF7FC <<>>$$&&#---- grv/A/A&B  F **CFFL&)tF44E>        6%-#7#7#77888886g7It/D/DhOO     6%,"8"8"88999996%.$:$:$::;;;;;;;rM   c                     t          j        ddt          j        gddd          t          j        g ddddg d	          g} | D ]}|                    d
          }|t          dddddddt          |          j        fddg	          k    sJ t                      }|                    |           dddddt          |          j         ddg}|
                                                                |k    sJ t          |j                  |
                                k    sJ |                    dd
          }|t          g d          k    sJ d
S )z.
    Test getting info for just a column.
          ?       @r"   r&   zm/s)r"   r&   r$   )ro   rp   g      @)FFT)r"   r&   r$   maskNr   r"   r"   )r   r4   r#   r6   )r$   zm / sr%   r6   )r&   r&   r!   r'   r   r(   r   zname = namezdtype = float64zunit = m / szdescription = descriptionzclass = z	n_bad = 1z
length = 3rQ   )rr   )rU   rY   )rV   r[   )rW   r\   )rX   r^   ru   rv   )r   Columnr:   nanMaskedColumnr=   r   typer>   r   rE   ri   rD   )colsr   cinfor   rk   s        rK   test_data_infor}      s   
 	#rvVU	
 	
 	
 	OO%%%%	
 	
 	
	D  .
 .
4   $!.$q''*+

 
 
 
 
 
 jj	3')tAww'))
 ||~~((**c1111 AF||s||~~---- wD))  

 

 

 

 

 

 

I.
 .
rM   c                       G d dt           j                  } g ddgfD ]Q} | |d          }|                    d           }|t          dd	d
dddddt	          |          fg          k    sJ Rd S )Nc                       e Zd ZdZdS )'test_data_info_subclass.<locals>.ColumnzI
        Confusingly named Column on purpose, but that is legal.
        N)r>   
__module____qualname____doc__rb   rM   rK   rw   r      s        	 	 	rM   rw   r   r   int64r   r   )r   r   rs   )r$   r6   rt   )r&   r6   )r!   rw   )r'   r   r(   )r   rw   r=   r   len)rw   datar   r|   s       rK   test_data_info_subclassr      s            aV 
 
F4w'''4  "##3t99%	
 
 
 
 
 
 

 
rM   c                      t          j        d          } |                     d          }|d         dk    sJ d|vsJ dS )z1
    Make sure info works with scalar values
    z2000:001Nr   r'   r   r(   )r   r8   r=   )r   r|   s     rK   test_scalar_infor      sR     		*AFFtFE>Q5      rM   c                      t          j                    } t                      }|                     |           ddg}|                                                                |k    sJ d S )Nr   z<Table length=0>z<No columns>)r   r<   r   r=   rE   ri   )rG   r   rk   s      rK   test_empty_tabler     s\    A
**CFFsFOOO~
.C<<>>$$&&#------rM   c                  P   dgt           j        z  dgt           j        z  g} g d}g d}t          j        |ft          j        |ffD ]`\  }} ||           }t                      }|                    |           |                                                                |k    sJ adS )z]
    Test that class info column is suppressed only for identical non-mixin
    columns.
    r   r   )z<Table length=1>zname  dtype  unitz---- ------- ----zcol0 float64    mzcol1 float64    m)z<QTable length=1>zname  dtype  unit  class  z---- ------- ---- --------zcol0 float64    m Quantityzcol1 float64    m Quantityr   N)	rA   r7   r   r<   QTabler   r=   rE   ri   )valstexpqexp	table_clsrk   rG   r   s          rK   test_class_attributer     s    
 C!#IsQSy!D  D  D "K.t0DE 2 2	3IdOOjj	3||~~((**c11111	2 2rM   c                     t          j        t          j        t          j        gg          } t	          j        d          5 }|                     dd            t          |          dk    sJ 	 d d d            d S # 1 swxY w Y   d S )NTrecordrQ   r   r   )r   r<   r:   rx   warningscatch_warningsr=   r   rG   warnss     rK   test_ignore_warningsr   ,  s    bfbf%&''A		 	-	-	- 	wD!!!5zzQ                 s   -A<<B B c                      t                      } t          j        d          5 }|                                  t	          |          dk    sJ 	 d d d            d S # 1 swxY w Y   d S )NTr   r   )r   r   r   r=   r   r   s     rK   test_no_deprecation_warningr   3  s     	A		 	-	-	- 	5zzQ                 s   *AA #A c                      t          j        g dd          } t          j        t          d          5  | d d          j        j         d d d            d S # 1 swxY w Y   d S )Nr   r   )r"   z!failed to access "info" attribute)match)r   rw   pytestraisesAttributeErrorr=   r"   )r   s    rK   test_lost_parent_errorr   <  s    YYYS)))A	~-P	Q	Q	Q  	!!!	                 s   AAAc            
         t          j        t          j        ddgd          t	          j        ddgddgd          t          j        ddgddg	          t          j        ddgddg	          d
          i } dD ]$t                   j        j	                  | <   %t          ddd          5  dD ]0t          fd         j        j	        D                       sJ 1d         j        j	        | d         k    sJ t          d         j        d          rJ 	 ddd           n# 1 swxY w Y   dD ]          j        j	        |          k    sJ !t          d         j        d          rJ t          ddddt           j        di          5  dD ]0t          fd         j        j	        D                       sJ 1t          d         j        d          rJ 	 ddd           n# 1 swxY w Y   dD ]          j        j	        |          k    sJ !t          d         j        d          rJ t          d          5  dD ]0t          fd         j        j	        D                       sJ 1t          d         j        d          rJ 	 ddd           n# 1 swxY w Y   dD ]          j        j	        |          k    sJ !t          d         j        d          rJ dS )
    Unit test of context manager to set info.serialize_method.  Normally just
    used to set this for writing a Table to file (FITS, ECSV, HDF5).
    r   r   cxcsecr/   r0   r1   TF)rq   )tmscmcmc2)r   r   r   test_tmtest_mc)r   r   c              3   V   K   | ]#}         j         j        |         d z   k    V  $dS test_Nr=   serialize_method.0keyr"   rG   s     rK   	<genexpr>z-test_info_serialize_method.<locals>.<genexpr>W  N         $-c2gnD     rM   r   r   r   Nr   r   test_mc2c              3   V   K   | ]#}         j         j        |         d z   k    V  $dS r   r   r   s     rK   r   z-test_info_serialize_method.<locals>.<genexpr>h  r   rM   testc              3   P   K   | ] }         j         j        |         d k    V  !dS )r   Nr   r   s     rK   r   z-test_info_serialize_method.<locals>.<genexpr>v  sJ         $-c2f<     rM   )r   r<   r   r8   r   r9   ry   r   r=   r   r
   r@   hasattrrw   )origsr"   rG   s    @@rK   test_info_serialize_methodr   B  s   
 	)QF8444&1v1vEBBB$aV4-@@@%q!fD%=AAA		
 	
	 	A E# > >qw|<==d 
Qy	 B B	C	C = =  	 	D     T7<8         x}-u====1T7<);<<<<<<= = = = = = = = = = = = = = = $ < <w|,d;;;;;qw|%788888 
	D)T9elJG
 
 = = ( 	 	D     T7<8         1T7<);<<<<<<= = = = = = = = = = = = = = = $ < <w|,d;;;;;qw|%788888 
Q	'	' = =' 	 	D     T7<8         1T7<);<<<<<<= = = = = = = = = = = = = = = $ < <w|,d;;;;;qw|%78888888s9   7A/D33D7:D7AG<<H H AJ55J9<J9c                  h   t          d          t          d         j        j                  } 	 t	          d          5  t          fdd         j        j        D                       sJ t                      # 1 swxY w Y   n# t          $ r Y nw xY wd         j        j        | k    sJ dS )r   T)rg   r   r   c              3   P   K   | ] }d          j         j        |         dk    V  !dS )r   r   Nr   )r   r   rG   s     rK   r   z7test_info_serialize_method_exception.<locals>.<genexpr>  sJ         #,S1V;     rM   N)r   r   r=   r   r
   r@   ZeroDivisionError)r   rG   s    @rK   $test_info_serialize_method_exceptionr     s   
 	D!!!AQsV[122E F++ 	& 	&    S6;7        $%%%	& 	& 	& 	& 	& 	& 	& 	& 	&     S6;'5000000s/   B
 <A>>BB
 BB
 

BB)#r   collectionsr   copyr   ior   numpyr:   r   astropyr   r   r   r	   rA   astropy.table.infor
   astropy.table.table_helpersr   astropy.utils.data_infor   r   rL   rm   r}   r   r   r   r   r   r   r   r   r   rb   rM   rK   <module>r      s    # # # # # #                  , , , , , , , , , ,       2 2 2 2 2 2 4 4 4 4 4 4 F F F F F F F F4* 4* 4*nU< U< U<p>
 >
 >
B
 
 
2! ! !. . .2 2 2<      <9 <9 <9~1 1 1 1 1rM   