
    IR-e                         d dl Z d dl mZ d dlmZ d dlZ G d d          Ze j        j	        
                    e           dS )    N)OrderedDict)indexc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
d
 Zd Zd Zd Zed             Zed             Zd Zed             Zed             Zed             Zed             ZddZd Zd Zd Zd ZdS )Rowa  A class to represent one row of a Table object.

    A Row object is returned when a Table object is indexed with an integer
    or when iterating over a table::

      >>> from astropy.table import Table
      >>> table = Table([(1, 2), (3, 4)], names=('a', 'b'),
      ...               dtype=('int32', 'int32'))
      >>> row = table[1]
      >>> row
      <Row index=1>
        a     b
      int32 int32
      ----- -----
          2     4
      >>> row['a']
      2
      >>> row[1]
      4
    c                     t          |          }t          |          }|| k     s||k    r"t          d| dt          |                     ||z  | _        || _        d S )Nzindex z$ out of range for table with length )operator_indexlen
IndexError_index_table)selftabler   ns       1lib/python3.11/site-packages/astropy/table/row.py__init__zRow.__init__    sp    u%%JJA2::!PPPCJJPP  
 ai    c                 h    	 t          j         j        j        |           j                 }n# t
          t          f$ rp  j                            |          r6 fd|D             } j                            |d           j                 }n j        j        |          j                 }Y nw xY w|S )Nc                 *    g | ]}j         |         S  r   ).0namer   s     r   
<listcomp>z#Row.__getitem__.<locals>.<listcomp>7   s     ;;;dD);;;r   F)copy)	r   __getitem__r   columnsr   KeyError	TypeError_is_list_or_tuple_of_str	__class__)r   itemoutcolss   `   r   r   zRow.__getitem__/   s    	= )$+*=tDDT[QCC)$ 	= 	= 	={33D99 =;;;;d;;;k++Du+==dkJ k)$/<	= 
s   *. A>B/.B/c                     | j                             |          r$| j                             | j        ||           d S || j         j        |         | j        <   d S )N)colnamesvals)r   r   _set_rowr   r   )r   r!   vals      r   __setitem__zRow.__setitem__>   s[    ;//55 	9K  t# FFFFF58DK%dk222r   c                     | j         S N)r%   r   s    r   _ipython_key_completions_zRow._ipython_key_completions_D   s
    }r   c                 h    | j         j        rt          d          |                                 |k    S Nz;Unable to compare rows for masked table due to numpy.ma bugr   masked
ValueErroras_voidr   others     r   __eq__z
Row.__eq__G   s;    ; 	 M   ||~~&&r   c                 h    | j         j        rt          d          |                                 |k    S r/   r0   r4   s     r   __ne__z
Row.__ne__Q   s9    ; 	M   ||~~&&r   Nc                 p    |t          d          t          j        |                                           S )a  Support converting Row to np.array via np.array(table).

        Coercion to a different dtype via np.array(table, dtype) is not
        supported and will raise a ValueError.

        If the parent table is masked then the mask information is dropped.
        Nz Datatype coercion is not allowed)r2   npasarrayr3   )r   dtypes     r   	__array__zRow.__array__X   s1     ?@@@z$,,..)))r   c                 4    t          | j        j                  S r+   )r	   r   r   r,   s    r   __len__zRow.__len__e   s    4;&'''r   c              #   n   K   | j         }| j        j                                        D ]}||         V  d S r+   )r   r   r   values)r   r   cols      r   __iter__zRow.__iter__h   sJ      ;&--// 	 	Ce*	 	r   c                 >    | j         j                                        S r+   )r   r   keysr,   s    r   rE   zRow.keysm   s    {"'')))r   c                 *    |                                  S r+   )rC   r,   s    r   rA   z
Row.valuesp   s    }}r   c                     | j         S r+   r   r,   s    r   r   z	Row.tables   
    {r   c                     | j         S r+   )r   r,   s    r   r   z	Row.indexw   rH   r   c                 z   | j         | j        j                                        }t	          fd|D                       }| j        j        rKt	          fd|D                       }t          j                            |g|g| j	                  d         }n"t          j        |g| j	                  d         }|S )a  
        Returns a *read-only* copy of the row values in the form of np.void or
        np.ma.mvoid objects.  This corresponds to the object types returned for
        row indexing of a pure numpy structured array or masked array. This
        method is slow and its use is discouraged when possible.

        Returns
        -------
        void_row : ``numpy.void`` or ``numpy.ma.mvoid``
            Copy of row values.
            ``numpy.void`` if unmasked, ``numpy.ma.mvoid`` else.
        c              3   L   K   | ]}t          j        |                   V  d S r+   )r:   r;   r   rB   r   s     r   	<genexpr>zRow.as_void.<locals>.<genexpr>   s0      <<RZ__U+<<<<<<r   c              3   V   K   | ]#}t          |d           r|j                 ndV  $dS )maskFN)hasattrrO   rL   s     r   rM   zRow.as_void.<locals>.<genexpr>   sM        GJ73#7#7BU     r   )rO   r<   r   )r<   )
r   r   r   rA   tupler1   r:   maarrayr<   )r   r#   r&   rO   void_rowr   s        @r   r3   zRow.as_void{   s     {"))++<<<<t<<<<<; 	=    NR    D u{{D6dj{II!LHHxdj999!<Hr   c                     | j         j        S r+   )r   metar,   s    r   rV   zRow.meta   s    {r   c                     | j         j        S r+   )r   r   r,   s    r   r   zRow.columns   s    {""r   c                     | j         j        S r+   )r   r%   r,   s    r   r%   zRow.colnames   s    {##r   c                     | j         j        S r+   )r   r<   r,   s    r   r<   z	Row.dtype   s    {  r   Fc           	      B   | j         dk    r| j         n| j         t          | j                  z   }| j        ||dz            }| j        j        d| j          g}|j        r|                    d           |                    ||ddt          | j                             S )zV
        Display row as a single-line table but with appropriate header line.
        r      zindex=zmasked=Truer   )	max_widthtableid)	r   r	   r   r    __name__r1   append_base_repr_id)r   htmlr   r   
descr_valss        r   ra   zRow._base_repr_   s      $zQ

TZ#dkBRBR5REEAI-.n-/D
/D/DE
< 	-m,,,  *4MBt{OO4M4M ! 
 
 	
r   c                 .    |                      d          S )NTrc   ra   r,   s    r   _repr_html_zRow._repr_html_   s    T***r   c                 .    |                      d          S )NFrf   rg   r,   s    r   __repr__zRow.__repr__   s    U+++r   c                     | j         dk    r| j         n| j         t          | j                  z   }d                    | j        ||dz                                d                    S )Nr   
r[   r\   )r]   )r   r	   r   joinr   pformat)r   r   s     r   __str__zRow.__str__   s[    #zQ

TZ#dkBRBR5RyyEEAI$56>>>LLMMMr   c                 F    t          |                               d          S )Nzutf-8)strencoder,   s    r   	__bytes__zRow.__bytes__   s    4yy(((r   r+   )F)r_   
__module____qualname____doc__r   r   r)   r-   r6   r8   r=   r?   rC   rE   rA   propertyr   r   r3   rV   r   r%   r<   ra   rh   rj   ro   rs   r   r   r   r   r   
   s        *    9 9 9  ' ' '' ' '* * * *( ( (  
* * *     X   X  2     X  # # X# $ $ X$ ! ! X!
 
 
 
+ + +, , ,N N N) ) ) ) )r   r   )collectionsr   operatorr   r   numpyr:   r   abcSequenceregisterr   r   r   <module>r~      s        # # # # # # , , , , , ,    s) s) s) s) s) s) s) s)l   ! !# & & & & &r   