
    M/Ph#                     &   d Z ddlmZmZ ddlmZmZ ddlZdOdZ G d de	          Z
d	 Z G d
 de	          Z G d d          Z	  edPi ddddddddddddddddddddddd d!gd"d#d$dd%d!d&d!d'd!d(d!d)dd*dd+d,Z edPi dd-dddddddddddddddd#dddd.d/d!d d!gd"d#d$dd%d0d&d0d)dd'd!d(d!d*dd+d,Z edPi dddddddddddddddd1dd2ddd d3gd/d3d"d#d$dd%d4d&d4d)d5d'd4d(d4d*d5d+d6Z edPi dd7dd8dd9dd:ddd;d<dd=dddddd>d d!gd/d!d"d#d$dd?d#d%d@d&d@d)dd'd@d(d@d*dd+d,dAdBdCdDdEdFdGdHdIZ eeeeeJ          Z edKddLM          ZdN ZdS )Qa  
Provides a simple table class.  A SimpleTable is essentially
a list of lists plus some formatting functionality.

Dependencies: the Python 2.5+ standard library.

Installation: just copy this module into your working directory (or
   anywhere in your pythonpath).

Basic use::

   mydata = [[11,12],[21,22]]  # data MUST be 2-dimensional
   myheaders = [ "Column 1", "Column 2" ]
   mystubs = [ "Row 1", "Row 2" ]
   tbl = SimpleTable(mydata, myheaders, mystubs, title="Title")
   print( tbl )
   print( tbl.as_csv() )

A SimpleTable is inherently (but not rigidly) rectangular.
You should create it from a *rectangular* (2d!) iterable of data.
Each item in your rectangular iterable will become the data
of a single Cell.  In principle, items can be any object,
not just numbers and strings.  However, default conversion
during table production is by simple string interpolation.
(So you cannot have a tuple as a data item *and* rely on
the default conversion.)

A SimpleTable allows only one column (the first) of stubs at
initilization, concatenation of tables allows you to produce tables
with interior stubs.  (You can also assign the datatype 'stub' to the
cells in any column, or use ``insert_stubs``.) A SimpleTable can be
concatenated with another SimpleTable or extended by another
SimpleTable. ::

    table1.extend_right(table2)
    table1.extend(table2)


A SimpleTable can be initialized with `datatypes`: a list of ints that
provide indexes into `data_fmts` and `data_aligns`.  Each data cell is
assigned a datatype, which will control formatting.  If you do not
specify the `datatypes` list, it will be set to ``range(ncols)`` where
`ncols` is the number of columns in the data.  (I.e., cells in a
column have their own datatype.) This means that you can just specify
`data_fmts` without bothering to provide a `datatypes` list.  If
``len(datatypes)<ncols`` then datatype assignment will cycle across a
row.  E.g., if you provide 10 columns of data with ``datatypes=[0,1]``
then you will have 5 columns of datatype 0 and 5 columns of datatype
1, alternating.  Corresponding to this specification, you should provide
a list of two ``data_fmts`` and a list of two ``data_aligns``.

Cells can be assigned labels as their `datatype` attribute.
You can then provide a format for that lable.
Us the SimpleTable's `label_cells` method to do this.  ::

    def mylabeller(cell):
        if cell.data is np.nan:
            return 'missing'

    mytable.label_cells(mylabeller)
    print(mytable.as_text(missing='-'))


Potential problems for Python 3
-------------------------------

- Calls ``next`` instead of ``__next__``.
  The 2to3 tool should handle that no problem.
  (We will switch to the `next` function if 2.5 support is ever dropped.)
- Let me know if you find other problems.

:contact: alan dot isaac at gmail dot com
:requires: Python 2.5.1+
:note: current version
:note: HTML data format currently specifies tags
:todo: support a bit more of http://www.oasis-open.org/specs/tr9503.html
:todo: add labels2formatters method, that associates a cell formatter with a
       datatype
:todo: add colspan support to Cell
:since: 2008-12-21
:change: 2010-05-02 eliminate newlines that came before and after table
:change: 2010-05-06 add `label_cells` to `SimpleTable`
    )lmaplrange)cyclezip_longestNFc                 X   t                      }t          | d          5 }t          j        |          }|du rt	          |          }n|du rd}|du rNt                      }|D ]<}|r8|                    |d                    |                    |dd                    =n|D ]}|r|                    |           |du rd}ddd           n# 1 swxY w Y   t          |d                   t          fd	|D                       rt          d
          t          |||          S )a%  Return SimpleTable instance,
    created from the data in `csvfile`,
    which is in comma separated values format.
    The first row may contain headers: set headers=True.
    The first column may contain stubs: set stubs=True.
    Can also supply headers and stubs as tuples of strings.
    zutf-8)encodingTF r      Nc              3   >   K   | ]}t          |          k    V  d S Nlen).0rowncolss     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/iolib/table.py	<genexpr>zcsv2st.<locals>.<genexpr>w   s.      
-
-3s88u
-
-
-
-
-
-    z+All rows of CSV file must have same length.)dataheadersstubs)
listopencsvreadernextappendr   anyOSErrorSimpleTable)	csvfiler   r   titlerowsfhr   r   r   s	           @r   csv2str%   [   s    66D	g	(	(	( BBd??6llGGGD==FFE ) ) )LLQ(((KKABB((()
  % % %KK$$$E>>E#              $ QLLE

-
-
-
-
-
-
--- ECDDDD'????s   B#CCCc                       e Zd ZdZ	 	 	 ddZd Zd Zd Zdd	Zd
 Z	ddZ
ddZd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zed             ZdS )r    a  Produce a simple ASCII, CSV, HTML, or LaTeX table from a
    *rectangular* (2d!) array of data, not necessarily numerical.
    Directly supports at most one header row,
    which should be the length of data[0].
    Directly supports at most one stubs column,
    which must be the length of data.
    (But see `insert_stubs` method.)
    See globals `default_txt_fmt`, `default_csv_fmt`, `default_html_fmt`,
    and `default_latex_fmt` for formatting options.

    Sample uses::

        mydata = [[11,12],[21,22]]  # data MUST be 2-dimensional
        myheaders = [ "Column 1", "Column 2" ]
        mystubs = [ "Row 1", "Row 2" ]
        tbl = text.SimpleTable(mydata, myheaders, mystubs, title="Title")
        print( tbl )
        print( tbl.as_html() )
        # set column specific data formatting
        tbl = text.SimpleTable(mydata, myheaders, mystubs,
            data_fmts=["%3.2f","%d"])
        print( tbl.as_csv() )
        with open('c:/temp/temp.tex','w') as fh:
            fh.write( tbl.as_latex_tabular() )
    N c                    || _         || _        | j        <t          |          dk    rg n!t          t          |d                             | _        t                                          | _        t                                          | _        t                                          | _
        t                                          | _        | j
                            |           | j                            |           | j                            |           | j                            |           | j
                            |pt                                 | j                            |pt                                 | j                            |pt                                 | j                            |	pt                                 t          | j        | j
        | j        | j                  | _        |
pt           | _        |pt$          | _        |                     |          }t*                              | |           |                     ||           t                      | _        dS )a  
        Parameters
        ----------
        data : list of lists or 2d array (not matrix!)
            R rows by K columns of table elements
        headers : list (or tuple) of str
            sequence of K strings, one per header
        stubs : list (or tuple) of str
            sequence of R strings, one per stub
        title : str
            title of the table
        datatypes : list of int
            indexes to `data_fmts`
        txt_fmt : dict
            text formatting options
        ltx_fmt : dict
            latex formatting options
        csv_fmt : dict
            csv formatting options
        hmtl_fmt : dict
            hmtl formatting options
        celltype : class
            the cell class for the table (default: Cell)
        rowtype : class
            the row class for the table (default: Row)
        fmt_dict : dict
            general formatting options
        Nr   )txtr   htmllatex)r"   
_datatypesr   r   default_txt_fmtcopy_txt_fmtdefault_latex_fmt
_latex_fmtdefault_csv_fmt_csv_fmtdefault_html_fmt	_html_fmtupdatedictoutput_formatsCell_CellRow_Row
_data2rowsr   __init___add_headers_stubs
_colwidths)selfr   r   r   r"   	datatypescsv_fmttxt_fmtltx_fmthtml_fmtcelltyperowtypefmt_dictr#   s                 r   r>   zSimpleTable.__init__   s   > 
#?"$'IINNbbs47||8L8LDO',,..+0022',,..)..00 	X&&&X&&&x(((h'''W.///W.///w0$&&111h0$&&111"/	
 
 
 %
Ns	t$$dD!!!///&&r   c                 *    |                                  S r   )as_textrA   s    r   __str__zSimpleTable.__str__   s    ||~~r   c                 :    t          t          |                     S r   )strtyperL   s    r   __repr__zSimpleTable.__repr__   s    4::r   c                      | j         di |S )Nr	   )as_html)rA   rI   s     r   _repr_html_zSimpleTable._repr_html_   s    t|''h'''r   Tc                      | j         |fi |S r   )as_latex_tabular)rA   centerrI   s      r   _repr_latex_zSimpleTable._repr_latex_   s    $t$V88x888r   c                 n    |r|                      d|d           |r|                     d|           dS dS )ak  Return None.  Adds headers and stubs to table,
        if these were provided at initialization.
        Parameters
        ----------
        headers : list[str]
            K strings, where K is number of columns
        stubs : list[str]
            R strings, where R is number of non-header rows

        :note: a header row does not receive a stub!
        r   header_dec_below)	dec_belowN)insert_header_rowinsert_stubs)rA   r   r   s      r   r?   zSimpleTable._add_headers_stubs   sW      	M""1g9K"LLL 	(a'''''	( 	(r   c                     |	 |j         }n# t          $ r Y nw xY w|                     |||           }t                              | ||           dS )z1Return None.  Insert a row into a table.
        N)datatypetable)r_   AttributeErrorr<   r   insert)rA   idxr   r_   s       r   rb   zSimpleTable.insert   sk     <!   iihdi;;D#s#####s    
rZ   c           	      0   d |D             }t          t          |i t          d                    }|                                 t	          |          D ]>\  }}|                     ||d           |dk    r|| |         _        1d| |         _        ?dS )zReturn None.  Insert a row of headers,
        where ``headers`` is a sequence of strings.
        (The strings may contain newlines, to indicated multiline headers.)
        c                 8    g | ]}|                     d           S )
)split)r   headers     r   
<listcomp>z1SimpleTable.insert_header_row.<locals>.<listcomp>  s$    @@@fv||D))@@@r   r'   )	fillvaluerh   r_   r   N)r   r   r7   reverse	enumeraterb   r[   )rA   rownumr   r[   header_rowsr#   ir   s           r   r\   zSimpleTable.insert_header_row   s    
 A@@@@KCr0B0B0BCCDDoo 	. 	.FAsKKhK777Avv)2V&&)-V&&	. 	.r   c                    | j         }t          |          }| D ]r}|j        dk    r$ |dd          }|                    ||           1	 |                    |t          |                     V# t          $ r t          d          w xY wdS )zReturn None.  Insert column of stubs at column `loc`.
        If there is a header row, it gets an empty cell.
        So ``len(stubs)`` should equal the number of non-header rows.
        rh   r'   emptyrk   z'length of stubs must match table lengthN)r:   iterr_   rb   insert_stubr   StopIteration
ValueError)rA   locr   r:   r   
empty_cells         r   r]   zSimpleTable.insert_stubs  s    
 
U 	P 	PC|x''"U2888


3
++++POOCe5555$ P P P$%NOOOP	P 	Ps   #A//B	c                     | j         }| j        }g }|D ]Z}t          | j                  } ||d| |          }|D ]}t	          |          |_        ||_        |                    |           [|S )zCReturn list of Row,
        the raw data as rows of cells.
        r   )r_   r`   rG   )r:   r<   r   r,   r   r_   r   r   )	rA   raw_datar:   r<   r#   datarowdtypesnewrowcells	            r   r=   zSimpleTable._data2rows  s    
 
y 	  	 G4?++FT'F$OOOF " " $V!KKr   c                 $    t          |||          S )z%DEPRECATED: just use the pad function)pad)rA   swidthaligns       r   r   zSimpleTable.pad1  s    1eU###r   c                 V  	 t                    | j                                                                     |           t	          d | D                       }                    d          		dk    rdg|z  S 	dg|z  	nJt          	t                    r	g|z  	n.t          	          |k     r	fdt          |          D             	g }t          |  D ]3}t	          fd|D                       }|                    |           4t          t          |	          }|S )z2Return list, the calculated widths of each column.c              3   4   K   | ]}t          |          V  d S r   r   r   r   s     r   r   z-SimpleTable._get_colwidths.<locals>.<genexpr>:  s(      --CHH------r   	colwidthsr   Nc                 @    g | ]}|t                    z           S r	   r   )r   rp   requests     r   ri   z.SimpleTable._get_colwidths.<locals>.<listcomp>C  s)    GGGQwq3w<</0GGGr   c              3   P   K   | ] }t           |j        d fi           V  !dS )r   N)r   format)r   cfmtoutput_formats     r   r   z-SimpleTable._get_colwidths.<locals>.<genexpr>F  sA      OOa3xqx=@@C@@AAOOOOOOr   )get_output_formatr8   r.   r6   maxget
isinstanceintr   rangezipr   r   )
rA   r   rI   r   
min_widthscolmaxwidthresultr   r   s
    `      @@r   _get_colwidthszSimpleTable._get_colwidths5  sL   )-88!-05577

8-------''+&&a<<3;_cEkGG%% 	Hi%'GG\\E!!GGGG%,,GGGG
: 	( 	(COOOOO3OOOOOHh''''c:w//r   c           
      J   |g}t          |                                          D ]\  }}t          |t                    r%|                    |t          |          f           ?t          |t                    rD|                    |t          t          |                                                    f           |                    ||f           t          |          }	 | j        |         S # t          $ r&  | j	        |fi || j        |<   | j        |         cY S w xY w)z'Return list, the widths of each column.)
sorteditemsr   r   r   tupler7   r@   KeyErrorr   )rA   r   rI   	call_argskvkeys          r   get_colwidthszSimpleTable.get_colwidthsK  s=   "O	8>>++,, 	) 	)DAq!T"" )  !U1XX////At$$ )  !U6!''))+<+<%=%=!>????  !Q((((I	(?3'' 	( 	( 	(#64#6} $C $C9A$C $CDOC ?3''''	(s   %C2 2-D"!D"c                     t          |          }	 | j        |                                         }n # t          $ r t	          d|z            w xY w|                    |           |S -Return dict, the formatting options.
        Unknown format: %s)r   r8   r.   r   rv   r6   rA   r   rI   r   s       r   _get_fmtzSimpleTable._get_fmt]  s~     *-88	C%m499;;CC 	C 	C 	C1MABBB	C 	

8
s	   1 Ac                 6     | j         di |} | j        di |S )zXReturn string, the table in CSV format.
        Currently only supports comma separator.r   )r   r	   )r   rK   )rA   rI   r   s      r   as_csvzSimpleTable.as_csvj  s3     dm..X..t|""c"""r   c                     | j         di |fd| D             }t          |d                   }                    dd          }|r|                    d||z             | j        }|r@t          | j        |                    dd                    }|                    d|                               d	d
          }|r|                    ||z             d                    |          S )z!Return string, the table as text.r)   c                 *    g | ]} |j         di S )text)r   	as_stringr   r   r   s     r   ri   z'SimpleTable.as_text.<locals>.<listcomp>v  s+    GGG3-#-66#66GGGr   table_dec_above=r   title_alignr   table_dec_below-rf   r)   )r   r   r   rb   r"   r   r   join)rA   rI   formatted_rowsrowlenr   r"   r   r   s          @r   rK   zSimpleTable.as_textq  s    dm..X..GGGG$GGG^B'(( ''"3S99 	?!!!_v%=>>> 
 	,
FCGGM3,G,GHHE!!!U+++''"3S99 	<!!/F":;;;yy(((r   c                     | j         di |dg}| j        rd| j        z  }|                    |           |                    fd| D                        |                    d           d                    |          S )zReturn string.
        This is the default formatter for HTML tables.
        An HTML table formatter must accept as arguments
        a table and a format dictionary.
        r*   z<table class="simpletable">z<caption>%s</caption>c              3   2   K   | ]} |j         di V  dS )r*   Nr*   r   r   s     r   r   z&SimpleTable.as_html.<locals>.<genexpr>  s5      KKsmcm::c::KKKKKKr   z</table>rf   r   )r   r"   r   extendr   )rA   rI   r   r"   r   s       @r   rS   zSimpleTable.as_html  s     dm//h//78: 	)+dj8E!!%(((KKKKdKKKKKKj)))yy(((r   c                     | j         di |}g }|r|                    d           |d         pd}|d         pd}d}d}| |gz   D ]}	|	|k    rd}
n |	j        di |}
|
|k    r]|r*|                    |           |                    d           |
r/|                    d|
z             |s|                    |           |	|k    r"|                     |	j        dd	di|           |
}| j        rd
| j        z  }|                    |           |r|                    d           d                    |                              dd          S )ziReturn string, the table as a LaTeX tabular environment.
        Note: will require the booktabs package.r+   z\begin{center}r   r'   r   Nz\end{tabular}z\begin{tabular}{%s}r   z%%\caption{%s}z\end{center}rf   z$$ )r+   r	   )r   r   
get_alignsr   r"   r   replace)rA   rW   rI   r   r   r   r   prev_alignslastr   alignsr"   s               r   rV   zSimpleTable.as_latex_tabular  s    dm00x00 	5!!"3444/06B/06B4&= 	! 	!Cd{{'77377$$ <"))/:::"))*:;;; ?"))*@6*IJJJ& ?&--o>>>d{{%%!CM???3??A A A KK : 	)%
2E!!%((( 	3!!/222 yy((00s;;;r   c                 \    t          | |          D ]\  }}|                    |           dS )a  Return None.
        Extend each row of `self` with corresponding row of `table`.
        Does **not** import formatting from ``table``.
        This generally makes sense only if the two tables have
        the same number of rows, but that is not enforced.
        :note: To extend append a table below, just use `extend`,
        which is the ordinary list method.  This generally makes sense
        only if the two tables have the same number of columns,
        but that is not enforced.
        N)r   r   )rA   r`   row1row2s       r   extend_rightzSimpleTable.extend_right  s@     dE** 	 	JD$KK	 	r   c                 B    | D ]}|D ]} ||          }|||_         dS )zReturn None.  Labels cells based on `func`.
        If ``func(cell) is None`` then its datatype is
        not changed; otherwise it is set to ``func(cell)``.
        Nrk   )rA   funcr   r~   labels        r   label_cellszSimpleTable.label_cells  sL    
  	* 	*C * *T

$$)DM*	* 	*r   c                     d | D             S )Nc                     g | ]	}|j         
S r	   r   r   s     r   ri   z$SimpleTable.data.<locals>.<listcomp>  s    )))S)))r   r	   rL   s    r   r   zSimpleTable.data  s    ))D))))r   )
NNr'   NNNNNNN)Tr   )rZ   )__name__
__module____qualname____doc__r>   rM   rQ   rT   rX   r?   rb   r\   r]   r=   r   r   r   r   r   rK   rS   rV   r   r   propertyr   r	   r   r   r    r    |   s        2 >@EI7;>! >! >! >!@    ( ( (9 9 9 9( ( ("	$ 	$ 	$ 	$. . . . P P P"  $$ $ $  ,( ( ($  # # #) ) )0) ) ) .< .< .< .<`  	* 	* 	* * * X* * *r   r    c                     |dk    r|                      |          } n1|dk    r|                     |          } n|                     |          } | S )zCReturn string padded with spaces,
    based on alignment parameter.lr)ljustrjustrW   )r   r   r   s      r   r   r     sL     ||GGENN	#GGENNHHUOOHr   c                   Z    e Zd ZdZ	 	 ddZd Zd Zd Zd	 ZddZ	d Z
ed             ZdS )r;   zjProvides a table row as a list of cells.
    A row can belong to a SimpleTable, but does not have to.
    r   Nrow_dec_belowc                      | _         | _        |t          n|j         _        | _        t                       _        | _        t          	                      fd|D                        dS )aw  
        Parameters
        ----------
        seq : sequence of data or cells
        table : SimpleTable
        datatype : str ('data' or 'header')
        dec_below : str
          (e.g., 'header_dec_below' or 'row_dec_below')
          decoration tag, identifies the decoration to go below the row.
          (Decoration is repeated as needed for text formats.)
        Nc              3   2   K   | ]} |           V  dS ))r   Nr	   )r   r~   rG   rA   s     r   r   zRow.__init__.<locals>.<genexpr>  s2      FF$XXd555FFFFFFr   )
r_   r`   r9   r:   _fmtr7   special_fmtsr[   r   r>   )rA   seqr_   r`   rG   r[   rI   s   `   `  r   r>   zRow.__init__  s     !
} ;
	 FF"dFFFFF#FFFGGGGGr   c                     t          |          }|| j        vrt                      | j        |<   | j        |                             |           dS )z
        Return None. Adds row-instance specific formatting
        for the specified output format.
        Example: myrow.add_format('txt', row_dec_below='+-')
        N)r   r   r7   r6   )rA   r   rI   s      r   
add_formatzRow.add_format  sR     *-88 111/3vvDm,-(//99999r   c                     | j         }t          ||          s|} ||d|           }|                     ||           dS )zGReturn None.  Inserts a stub cell
        in the row at `loc`.
        stub)r_   r   N)r:   r   rb   )rA   rw   r   r:   s       r   rt   zRow.insert_stub  sR     
$&& 	:D5D999DCr   c                    t          |          }	 t          |                                         }n # t          $ r t	          d|z            w xY w	 |                    | j        j        |                    n# t          $ r Y nw xY w|                    | j	                   |                    |           | j
                            |d          }||                    |           |S )r   r   N)r   default_fmtsr.   r   rv   r6   r`   r8   ra   r   r   r   )rA   r   rI   r   special_fmts        r   r   zRow._get_fmt&  s    *-88	C}-2244CC 	C 	C 	C1MABBB	C	JJtz0?@@@@ 	 	 	D	 	

49

8'++M4@@"JJ{###
s   1 A%A8 8
BBc                 f     | j         fi |d                    fd| D                       S )zcReturn string, sequence of column alignments.
        Ensure comformable data_aligns in `fmt_dict`.r'   c              3   4   K   | ]} |j         fi V  d S r   )	alignment)r   r~   r   r   s     r   r   z!Row.get_aligns.<locals>.<genexpr>@  s7      MM~t~m;;s;;MMMMMMr   )r   r   r   s    ` @r   r   zRow.get_aligns<  sI     dmM66X66wwMMMMMMMMMMMr   r)   c                     | j         |fi |}	  | j        j        |fi |}n%# t          $ r |                    d          }Y nw xY w|dt          |           z  }|d         }|                    dd          }|                    dd          }g }t          | |          D ]*\  }	}
 |	j        |
fd|i|}|                    |           +||	                    |          z   |z   } | j
        ||fi |}|S )	a  Return string: the formatted row.
        This is the default formatter for rows.
        Override this to get different formatting.
        A row formatter must accept as arguments
        a row (self) and an output format,
        one of ('html', 'txt', 'csv', 'latex').
        r   N)r   colseprow_prer'   row_postr   )r   r`   r   ra   r   r   r   r   r   r   _decorate_below)rA   r   rI   r   r   r   r   r   formatted_cellsr~   r   contentformatted_rows                r   r   zRow.as_stringB  sR    dmM66X66	-0
0FF#FFII 	- 	- 	-,,III	-s4yy(IX'')R((77:r**tY// 	, 	,KD%!dk%LL}LLLG""7++++&++o">">>I,,]M 4 4/24 4s   $ AAc                 B   |                     | j        d          }||}n~t          |          }|dk    rHt          |          }t          |          }t	          ||          \  }}	|dz   ||z  |d|	         z   z   }n!|dk    r	|dz   |z   }nt          d|z            |S )zLThis really only makes sense for the text and latex output formats.
        Nr)   rf   r+   zI cannot decorate a %s header.)r   r[   r   r   divmodrv   )
rA   row_as_stringr   rI   r[   r   row0lendec_lenrepeataddons
             r   r   zRow._decorate_below`  s     LL66	"FF-m<<M%%m,,i.. &w 8 8&-V1C1:6E61B2C D'))&-	9 !A!."/ 0 0 0r   c                     d | D             S )Nc                     g | ]	}|j         
S r	   r   )r   r~   s     r   ri   zRow.data.<locals>.<listcomp>w  s    +++d	+++r   r	   rL   s    r   r   zRow.datau  s    ++d++++r   )r   NNr   r   )r   r   r   r   r>   r   rt   r   r   r   r   r   r   r	   r   r   r;   r;     s          CG*H H H H4	: 	: 	:    ,N N N   <  * , , X, , ,r   r;   c                   n    e Zd ZdZddZd Zd Zd Zed             Z	dd
Z
d Zd Z eee          ZdS )r9   zQProvides a table cell.
    A cell can belong to a Row, but does not have to.
    r'   Nc                     t          |t                    r%|j        | _        |j        | _        |j        | _        n!|| _        || _        t                      | _        | j                            |           || _        d S r   )	r   r9   r   r_   	_datatyper   r7   r6   r   )rA   r   r_   r   rI   s        r   r>   zCell.__init__~  sk    dD!! 		DI!]DN	DIIDI%DNDI	"""r   c                     d| j         z  S )N%sr   rL   s    r   rM   zCell.__str__  s    dir   c                    t          |          }	 t          |                                         }n # t          $ r t	          d|z            w xY w	 |                    | j        j        j        |                    n# t          $ r Y nw xY w	 |                    | j        j
                   n# t          $ r Y nw xY w|                    | j
                   |                    |           |S r   )r   r   r.   r   rv   r6   r   r`   r8   ra   r   r   s       r   r   zCell._get_fmt  s    *-88	C}-2244CC 	C 	C 	C1MABBB	C	JJtx~4]CDDDD 	 	 	D		JJtx}%%%% 	 	 	D	 	

49

8
s-   1 A*A= =
B
	B
B. .
B;:B;c                     | j         |fi |}| j        }|                    dd          }t          |t                    r||t          |          z           }nd|dk    r,|                    d          p|                    dd          }n2||v rd|z  }|                    |d          }nt          d|z            |S )	Ndata_alignsr   r   stubs_align
stub_alignr   z%s_alignUnknown cell datatype: %s)r   r_   r   r   r   r   rv   )rA   r   rI   r   r_   r  r   label_aligns           r   r   zCell.alignment  s    dmM66X66=ggmS11h$$ 		E3{+;+; ;<EEGGM**HcgglC.H.HEE__$x/KGGK--EE88CDDDr   c                     |dk    r| S d|v rOt          | t                    r:t          |d                   D ]$}|                     ||d         |                   } %| S )Nr+   replacements)r   rO   r   r   )r   r   r   repls       r   _latex_escapezCell._latex_escape  sr    G##KS  $$$ I"3~#677 I ID<<c..A$.GHHDDr   r)   c                     | j         |fi |}| j        }| j        }|                    d          }||                    d          }|d}|g}t	          |t
                    r~|t          |          z  }||         }t	          |t                    r||fz  }	n*t          |          r ||          }	nt          d          |dk    r| 
                    |	||          }	n\||v rF| 
                    |||          }|                    |          }
	 |
|fz  }	n$# t          $ r |
}	Y nw xY wt          d|z             | j        |fi |}t          |	||          S )ac  Return string.
        This is the default formatter for cells.
        Override this to get different formating.
        A cell formatter must accept as arguments
        a cell (self) and an output format,
        one of ('html', 'txt', 'csv', 'latex').
        It will generally respond to the datatype,
        one of (int, 'header', 'stub').
        	data_fmtsNdata_fmtr  zMust be a string or a callabler   r	  )r   r   r_   r   r   r   r   rO   callable	TypeErrorr  rv   r   r   )rA   r   r   rI   r   r   r_   r  r  r   dfmtr   s               r   r   zCell.format  s    dmM66X66y=GGK((	wwz**H!
Ih$$ 	E#i..0H *H(C(( B"dW,(## B"(4.. @AAA1}},,Wc=II__%%dC??D778$$D$.    88CDDD}44447E5)))s   D D*)D*c                 <    | j         | j        j        }n| j         }|S r   )r  r   r_   )rA   dtypes     r   get_datatypezCell.get_datatype  s"    >!H%EENEr   c                     || _         d S r   )r  )rA   vals     r   set_datatypezCell.set_datatype  s    r   )r'   NNr   )r   r   r   r   r>   rM   r   r   staticmethodr  r   r  r  r   r_   r	   r   r   r9   r9   z  s                   0      \+* +* +* +*Z     xl33HHHr   r9   r   r)   r   r   r   r   r   r   r   r'   r   rZ   r   r   r   r   r  r   r  r  r  r   header_align
header_fmtstub_fmtrh   r   rx   rr   missingz--r   ,r  z"%s"z<tr>
  z
</tr>z<td>%s</td>z<th>%s</th>z	<td></td>z<td>--</td>ltxz\toprulez\bottomrulez\midrulestrip_backslashTz  \\z & empty_alignz\textbf{%s}r  z\#z\$z\%z\&z$>$z\_z$|$)#$%&>_|r*   r)   r+   r   r*   r+   )htmr   r!  c                 l    | dvr/	 t           |          } n # t          $ r t          d| z            w xY w| S )Nr+  zunknown output format %s)output_format_translationsr   rv   )r   s    r   r   r     sY    ;;;	I6}EMM 	I 	I 	I7-GHHH	Is    1)FFNr	   )r   statsmodels.compat.pythonr   r   	itertoolsr   r   r   r%   r   r    r   r;   r9   r7   r-   r2   r4   r0   r   r.  r   r	   r   r   <module>r1     s  R Rh 3 2 2 2 2 2 2 2 ( ( ( ( ( ( ( ( 



@ @ @ @Bh* h* h* h* h*$ h* h* h*V	 	 	D, D, D, D, D,$ D, D, D,N}4 }4 }4 }4 }4 }4 }4 }4B $    C C	
  B R S $ d 3   ff!& s'( ), t-. T/0 412 
34 r56 "78 D9> $   D D
 B R T $   d 3 T ff$ s%& '* v+, V-. r/0 412 
34 "56 D7< 4   D D T	
 $  d 3 J Y  oo ]$ s%& '* }+, ]-. {/0 =12 
34 +56 M7 < D % % %%  K% #N	%
 ![% $% D% W% % d% 5% ff% T%$ s%%& '%( )%, ~-%. ^/%0 r1%2 >3%4 
5%6 "7%8 D9%<   =% N t	
	   "T	       r   