B
    d                 @   sH   d dl Z d dl mZ d dlmZ d dlZG dd dZe jj	
e dS )    N)OrderedDict)indexc               @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	d2d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edd  Zed!d" Zed#d$ Zed%d& Zd3d(d)Zd*d+ Zd,d- Zd.d/ Zd0d1 ZdS )4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             C   sJ   t |}t|}|| k s"||kr6td|t||| | _|| _d S )Nz.index {} out of range for table with length {})operator_indexlen
IndexErrorformat_index_table)selftabler   n r   ^/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/astropy/table/row.py__init__    s    
zRow.__init__c          	      s   yt  jj| j }W n` ttfk
rz    j|rd fdd|D } jj|dd j }n jj|  j }Y nX |S )Nc                s   g | ]} j | qS r   )r
   ).0name)r   r   r   
<listcomp>6   s    z#Row.__getitem__.<locals>.<listcomp>F)copy)	r   __getitem__r
   columnsr	   KeyError	TypeError_is_list_or_tuple_of_str	__class__)r   itemoutcolsr   )r   r   r   .   s    zRow.__getitem__c             C   s8   | j |r"| j j| j||d n|| j j| | j< d S )N)colnamesvals)r
   r   Z_set_rowr	   r   )r   r   valr   r   r   __setitem__=   s    zRow.__setitem__c             C   s   | j S )N)r   )r   r   r   r   _ipython_key_completions_C   s    zRow._ipython_key_completions_c             C   s   | 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   otherr   r   r   __eq__F   s    z
Row.__eq__c             C   s   | j jrtd|  |kS )Nz;Unable to compare rows for masked table due to numpy.ma bug)r
   r#   r$   r%   )r   r&   r   r   r   __ne__N   s    z
Row.__ne__Nc             C   s   |dk	rt dt|  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)r$   npasarrayr%   )r   dtyper   r   r   	__array__S   s    zRow.__array__c             C   s   t | jjS )N)r   r
   r   )r   r   r   r   __len__`   s    zRow.__len__c             c   s*   | j }x| jj D ]}|| V  qW d S )N)r	   r
   r   values)r   r   colr   r   r   __iter__c   s    zRow.__iter__c             C   s   | j j S )N)r
   r   keys)r   r   r   r   r1   h   s    zRow.keysc             C   s   |   S )N)r0   )r   r   r   r   r.   k   s    z
Row.valuesc             C   s   | j S )N)r
   )r   r   r   r   r   n   s    z	Row.tablec             C   s   | j S )N)r	   )r   r   r   r   r   r   s    z	Row.indexc       	         s   | j | jj }tfdd|D }| jjrddlm  tfdd|D } fdd|D }dd |D }tj	|g|d	d
 }tj	|g| j
d	d
 }tjj||d}ntj	|g| j
d	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   s   | ]}t |  V  qd S )N)r)   r*   )r   r/   )r   r   r   	<genexpr>   s    zRow.as_void.<locals>.<genexpr>   )descrc             3   s&   | ]}t |d r|j  ndV  qdS )maskFN)hasattrr5   )r   r/   )r   r   r   r2      s   c             3   s   | ]} |V  qd S )Nr   )r   r/   )r4   r   r   r2      s    c             S   s   g | ]\}}}|t |fqS r   )bool)r   r   type_shaper   r   r   r      s    zRow.as_void.<locals>.<listcomp>)r+   r   )datar5   )r	   r
   r   r.   tupler#   r   r4   r)   arrayr+   maZmvoid)	r   r   r   masksZdescrsZmask_dtypesZrow_maskZrow_valsZvoid_rowr   )r4   r   r   r%   v   s    
zRow.as_voidc             C   s   | j jS )N)r
   meta)r   r   r   r   r?      s    zRow.metac             C   s   | j jS )N)r
   r   )r   r   r   r   r      s    zRow.columnsc             C   s   | j jS )N)r
   r   )r   r   r   r   r      s    zRow.colnamesc             C   s   | j jS )N)r
   r+   )r   r   r   r   r+      s    z	Row.dtypeFc             C   st   | j dkr| j n| j t| j }| j||d  }| jjd| j  g}|jrV|d |j||ddt| j dS )zV
        Display row as a single-line table but with appropriate header line.
        r   r3   zindex=zmasked=Truer   )	max_widthZtableid)	r   r   r
   r   __name__r#   append_base_repr_id)r   htmlr   r   Z
descr_valsr   r   r   rD      s     

zRow._base_repr_c             C   s   | j ddS )NT)rF   )rD   )r   r   r   r   _repr_html_   s    zRow._repr_html_c             C   s   | j ddS )NF)rF   )rD   )r   r   r   r   __repr__   s    zRow.__repr__c             C   s@   | j dkr| j n| j t| j }d| j||d  jddS )Nr   
r3   r@   )rA   )r   r   r
   joinr   pformat)r   r   r   r   r   __str__   s     zRow.__str__c             C   s   t | dS )Nzutf-8)strencode)r   r   r   r   	__bytes__   s    zRow.__bytes__)N)F)rB   
__module____qualname____doc__r   r   r!   r"   r'   r(   r,   r-   r0   r1   r.   propertyr   r   r%   r?   r   r   r+   rD   rG   rH   rL   rO   r   r   r   r   r   
   s0   
%
r   )collectionsr   operatorr   r   numpyr)   r   abcSequenceregisterr   r   r   r   <module>   s    >