Tabular Classes for PyTabular Package

Superclasses:

  • TabularBase
  • Tabular2D
  • Tabular1D

Classes for User:

  • TabularCell
  • Tabular
  • Table
  • LongTable

Issues:

  • Should use regular expressions to handle LateX special characters when initializing TabularCell instances
class pytabular.core.tables.LongTable(content)

class for LateX longtables

set_caption(caption)

sets caption for the table

caption : str
caption of the table
set_label(label)

sets label for the table

label : str
label for the table
set_location(loc='c')

horizontal location (justification) of table

loc : str
‘c’ for center, ‘l’ for left and ‘r’ for right
set_repeats(repeats)

sets number of rows to repeat

repeats : int
number of rows to repeat on each page
class pytabular.core.tables.Table(content)

class for LateX tables

as_tex()

creates tex string for the row

set_caption(caption)

sets caption for the table

caption : str
caption of the table
set_label(label)

sets label for the table

label : str
label for the table
set_location(loc='c')

horizontal location (justification) of table

loc : str
‘c’ for center, ‘l’ for left and ‘r’ for right
class pytabular.core.tables.Tabular(content)

end-user class for LateX tabular environment

add_environment(env, post='', prepend=False)

adds an environment around tabular

env : str
name of latex environment, e.g. ‘center’
post : str
text to add after the initializion of environment
add_note(notes, fontsize='scriptsize')

sets the footnotes for the table

notes : str
notes to put in table
fontsize : str
LateX fontsize, e.g. ‘tiny’, ‘large’
as_tex()

creates tex string for the row

set_indent(indent)

sets indentation for presentation of output

indent : str
number of spaces to insert at indentation level
set_tab_alignment(tabular)

sets default alignment of tabular

tabular : str
must have alignment character for each column in table ex. ‘cc’, ‘p{3cm}ll’
write(filename)

write table to file

filename : str
name of file
class pytabular.core.tables.Tabular1D(content, orientation=0)

1-dimensional tabular

orientation : int
0 if horizontal, 1 if vertical
merge(force=False)

merges the 1-d tabular

force : bool
if True, forces merge over non-null cells, purges these cells
class pytabular.core.tables.Tabular2D(content, rowfragment=True, colfragment=True)

2-dimensional tabular

To be used as a superclass for TabularRow and TabularColumn Also can be directly accessed by slicing a Table

Must write over any methods in TabularBase which should operate on a per cell basis

flatten()

returns 1-d tabular of content

merge(force=False)

merges the Tabular2D

force : bool
if True, forces merge over non-null cells, purges these cells
set_alignment(alignment)

sets alignment of tabular element

alignment : str
alignment string in LateX ex: ‘c’, ‘l’, or ‘r’
set_bold(bold=True)

set to bold

bold : bool
True to bold
set_color(color, opacity=50)

sets color of cells

color : str
name of a color, some examples include: white, black, red, green, blue, cyan, magenta, yellow, gray
opacity : int
int in [0,100]
set_digits(digits=3)

gives value ‘digits’ signficant digits

digits : int
number of significant digits
set_emph(emph=True)

set to emph

emph : bool
True to emph
set_fontsize(fontsize)

sets fontsize

fontsize : str
font size for tabular element
set_formatter(formatter)

sets function to format content

formatter : function
function to format the content, must return a string
set_lines(lines='_', narrow=None)

adds a horizontal line below the cell

lines : str
‘-‘, ‘_’ for single line, ‘=’ for a double line
narrow : str
‘r’, ‘l’, or ‘lr’
set_mergedcol(mergedcol=True)

sets cells to mergedcol

mergedcol : bool
True to hide element
set_mergedrow(mergedrow=True)

sets cells to mergedrow

mergedrow : bool
True to hide element
set_rotation(angle)

sets rotation

angle : int
0 to 90
set_space_above(space)

set the spacing before a cell in a row

space : str, int, float
spacing to place after row (ex. ‘1cm’)

if numeric type give for space, assumes unit is ‘cm’

set_space_below(space)

set the spacing after a cell in a row

space : str, int, float
spacing to place after row (ex. ‘1cm’)

if numeric type give for space, assumes unit is ‘cm’

set_stars(side='left', levels=[0.1, 0.05, 0.01])

sets cell to display significance stars

side : str
‘left’ to apply on leftside of value, ‘right’ to apply on right side
levels : list
list for which to apply significance stars
set_underline(underline=True)

set to underline

underline : bool
True to underline
class pytabular.core.tables.TabularBase(content)

base tabular object

content : scalar type
str, int, float, long
as_tex()

render the tabular element as text

Must implement in subclass

get_attr(attr='all')

returns attribute(s) of the table element

attr : str
attribute of the table element
set_attr(**kwargs)

sets attributes

kwargs : keyword arguments
attributes to set
set_content(content)

sets content of tabular element

content : scalar type
content to replace with
class pytabular.core.tables.TabularCell(content, loc)

cell of a table

** Attributes ** shape : ()

empty tuple
ndim : int
0
rows : int
number of rows represented by cell (think multirow)
columns : int
number columns represented by cell (think multicolumn)
rotation : int or None
None if not rotated, int between 0 and 90 degrees
underline : bool
True to underline, false otherwise
bold : bool
True to bold, false otherwise
emph : bool
True to emphasize (italics), false otherwise
alignment : None
None to retain alignment of outer environment, else specify a string (e.g. ‘c’, ‘l’ or ‘r’)
formatter : function
Default is str, specify a function which takes a scalar type and outputs a string
fontsize : int or None
None to retain fontsize of outer environment, else specify a string (e.g. ‘small’, ‘tiny’)
phantom : bool
If True, the tabular element will not produce any string
hline : bool
If True, places horizontal line below cell
loc : tuple
(row, col) coordinates in table
as_tex()

render the tabular element as text

val : str
string which LateX will recognize in tabular environment
set_alignment(alignment)

sets alignment of tabular element

alignment : str
alignment string in LateX ex: ‘c’, ‘l’, or ‘r’
set_bold(bold=True)

set to bold

bold : bool
True to bold
set_color(color, opacity=50)

sets color of a cell

color : str
name of a color, some examples include: white, black, red, green, blue, cyan, magenta, yellow, gray
opacity : int
int in [0,100]
set_digits(digits=3)

gives value ‘digits’ signficant digits

digits : int
number of significant digits
set_emph(emph=True)

set to emph

emph : bool
True to emph
set_fontsize(fontsize)

sets fontsize

fontsize : str
font size for tabular element
set_formatter(formatter)

sets function to format content

formatter : function
function to format the content, must return a string
set_lines(lines='_', narrow=None)

adds lines around cell

lines : str
‘-‘ or ‘_’ for a single line, ‘=’ for a double line if None, assures no line is printed
narrow : str
‘r’, ‘l’, ‘lr’, or ‘rl’
set_mergedcol(mergedcol=True)

means cell is merged into another col

mergedcol : bool
True to hide element
set_mergedrow(mergedrow=True)

means cell is merged into another row

mergedrow : bool
True to hide element
set_rotation(angle)

sets rotation

angle : int
0 to 360
set_space_above(space)

set the spacing before the cell in row

space : str, int, float
spacing to place after row (ex. ‘1cm’)

if numeric type give for space, assumes unit is ‘cm’

set_space_below(space)

set the spacing after the cell in row

space : str, int, float
spacing to place after row (ex. ‘1cm’)

if numeric type give for space, assumes unit is ‘cm’

set_stars(side='left', levels=[0.1, 0.05, 0.01])

sets cell to display significance stars

side : str
‘left’ to apply on leftside of value, ‘right’ to apply on right side
levels : list
list for which to apply significance stars
set_underline(underline=True)

set to underline

underline : bool
True to underline
class pytabular.core.tables.TabularColumn(content)

tabular for a row

merge(force=False)

merges the row

force : bool
if True, forces merge over non-null cells, purges these cells
class pytabular.core.tables.TabularRow(content)

tabular for a row

as_tex(indent=2)

creates tex string for the row

merge(force=False)

merges the row

force : bool
if True, forces merge over non-null cells, purges these cells
pytabular.core.tables.hstack(*args)

stacks tabular objects horizontally

args : tuple
tabular objects, t1, t2, ...
tab : tabular instance
a new table
pytabular.core.tables.vstack(*args)

stacks tabular objects vertically

args : tuple
tabular objects, t1, t2, ...
tab : tabular instance
a new table
pytabular.core.operators.texCommands()

tex commands required for tables

tex : str
string to put in header of latex file

Formatters for Package PyTabular

pytabular.core.formatting.format_digits(digits=3)

formatter creator for significant digits

digits : int
number of significant digits
f : function
function to formal a value to digits significant digits
pytabular.core.formatting.format_int(val)

formats an integer

val : scalar type
value to formatted
val : str
formatted value
pytabular.core.formatting.format_stars(side='left', levels=[0.1, 0.05, 0.01], formatter=<type 'str'>)

formatter creator for significance stars

levels : list
list for which to apply significance stars
side : str
‘left’ to apply on leftside of value, ‘right’ to apply on right side
f : function
function to star value

Table Of Contents

This Page