mooonpy.tools.tables module

class mooonpy.tools.tables.ArrayTable(from_numpy=None, shape=None, collabels=None, rows=None, title=None, cornerlabel=None, default=Ellipsis)[source]

Bases: Table

col(key)[source]
headers() List[str] | None[source]
row(row_key)[source]
rowcol(row_key, key)[source]
rowlabels() List[str] | None[source]
shape() Tuple[int | None, int | None][source]
class mooonpy.tools.tables.ColTable(from_dict=None, rows=None, title=None, cornerlabel=None, default=Ellipsis)[source]

Bases: Table

col(key)[source]
headers() List[str] | None[source]
classmethod read_csv(file: Path | str, header=True, rowlabels=False, keep_list=None)[source]

Read csv file into columns

row(row_key)[source]
rowcol(row_key, key)[source]
rowlabels() List[str] | None[source]
shape() Tuple[int | None, int | None][source]
class mooonpy.tools.tables.ListListTable(from_listlist=None, shape=None, collabels=None, rows=None, title=None, cornerlabel=None, default=Ellipsis)[source]

Bases: Table

append(row)[source]

Append to ehd of grid

col(key)[source]
headers() List[str] | None[source]
classmethod read_csv(file: Path | str, header=True, rowlabels=False)[source]

Read csv file into columns

row(row_key)[source]
rowcol(row_key, key)[source]
rowlabels() List[str] | None[source]
shape() Tuple[int | None, int | None][source]
class mooonpy.tools.tables.Table(title=None, cornerlabel=None, default=Ellipsis)[source]

Bases: object

The Table object takes several form-factors of the underlying data structure implemented in its subclasses. The main class is a dummy for storage but handles IO to csv or text. Methods are developed so access can be aliased for any of the subclasses. Or the .grid attribute can be used for direct access on specific subclasses.

def shape(self) -> Tuple[Optional[int], Optional[int]]:

‘’’ Size of the grid attribute, similar to numpy’s .shape attribute. If one item in the tuple is None, the grid is asymmetric or does not match the labels and shape is meaningless. ‘’’ return tuple((0,0)) # makes code happy

def headers(self) -> Optional[List[str]]:

‘’’ Return a list of keywords or headers of the table ‘’’ pass

def rowlabels(self) -> Optional[List[str]]:

‘’’ Returns a list of row labels of the table ‘’’ pass

def col(self,key):

‘’’ Returns column from index of ‘key’ in headers, or if not found, index of the header if that fails, a column of appropriate length is created with .default ‘’’ pass

def row(self,row_key):

‘’’ Returns a row from the index of ‘row_key’ in rows, or if not found is used as the index This has O(N) cost if using ‘rowlabel’ as a list, or O(1) cost without the list ‘’’ pass

def rowcol(self,row_key,key):

pass

col_fun(fun_name: str) Dict | List[source]

Compute aggregate functions on each column.

The result is added to the summary dict as a ‘fun_name’:dict(key:value,…)

pair if keywords are defined, or a list(value,…) if not.

note that the summary dict may be converted to a RowTable

RowTable does not exist yet

The data is also returned.

console(**kwargs)[source]

Convert table to string representation This is ok to use in console for small tables, but will struggle for file IO with large tables

copy()[source]
csv(file: Path | str, append=False, skip_header=False)[source]

Write table to csv file

plot(**kwargs)[source]
yield_line()[source]

Create one line of a table with a specified format Will probably only work for rectangular tables