interregnum.bidimensional package¶
A bi-dimensional structure useful for graph or table operations.
- class interregnum.bidimensional.Bidimensional¶
Bases:
Generic[_Row,_Col,AnyValue]Bi-dimensional structure.
- __getitem__(idx)¶
Return the value at position idx (row index, col index).
- Parameters:
idx (tuple[_Row, _Col])
- Return type:
AnyValue
- col_size()¶
Return the number of columns.
- Return type:
int
- empty()¶
Return True if the object is empty.
- Return type:
bool
- iter_col(col, sparse=False)¶
Iterate column _Col elements.
- Parameters:
col (_Col)
sparse (bool)
- Return type:
Iterator[tuple[_Row, AnyValue]]
- iter_col_keys()¶
Iterate column keys.
- Return type:
Iterator[_Col]
- iter_row(row, sparse=False)¶
Iterate row _Row elements.
- Parameters:
row (_Row)
sparse (bool)
- Return type:
Iterator[tuple[_Col, AnyValue]]
- iter_row_keys()¶
Iterate row keys.
- Return type:
Iterator[_Row]
- remove_row(row)¶
Remove row _Row.
- Parameters:
row (_Row)
- Return type:
None
- row_size()¶
Return the number of rows.
- Return type:
int
Submodules¶
interregnum.bidimensional.dataframe module¶
A poor man’s data frame.
- class interregnum.bidimensional.dataframe.DataFrame¶
Bases:
Bidimensional[AnyKey,int,AnyValue]Table for series of data.
Create an empty data frame.
- __getitem__(idx)¶
Return the value at position idx (row index, col index).
- Parameters:
idx (tuple[AnyKey, int])
- Return type:
AnyValue
- col_size()¶
Return the number of columns.
- Return type:
int
- empty()¶
Return True if the object is empty.
- Return type:
bool
- insert_row(row, series)¶
Insert or replace a row.
- Parameters:
row (AnyKey)
series (list[AnyValue])
- Return type:
None
- iter_col(col, sparse=False)¶
Iterate column _Col elements.
- Parameters:
col (int)
sparse (bool)
- Return type:
Iterator[tuple[AnyKey, AnyValue]]
- iter_col_keys()¶
Iterate column keys.
- Return type:
Iterator[int]
- iter_row(row, sparse=False)¶
Iterate row _Row elements.
- Parameters:
row (AnyKey)
sparse (bool)
- Return type:
Iterator[tuple[int, AnyValue]]
- iter_row_keys()¶
Iterate row keys.
- Return type:
Iterator[AnyKey]
- remove_row(row)¶
Remove row _Row.
- Parameters:
row (AnyKey)
- Return type:
None
- row_size()¶
Return the number of rows.
- Return type:
int
interregnum.bidimensional.matrix module¶
Matrix structure with indices of a hashable type and values of any type.
- class interregnum.bidimensional.matrix.AbstractMatrix¶
Bases:
Bidimensional[_Row,_Col,AnyValue]Abstract matrix.
- __getitem__(idx)¶
Return the value at position idx (row index, col index).
- Parameters:
idx (tuple[_Row, _Col])
- Return type:
AnyValue
- __str__()¶
Return str(self).
- Return type:
str
- col(idx)¶
Return col.
- Parameters:
idx (_Col)
- Return type:
dict[_Row, AnyValue]
- col_size()¶
Return the number of columns.
- Return type:
int
- empty()¶
Return True if the object is empty.
- Return type:
bool
- iter_col(col, sparse=False)¶
Iterate column _Col elements.
- Parameters:
col (_Col)
sparse (bool)
- Return type:
Iterator[tuple[_Row, AnyValue]]
- iter_col_keys()¶
Return col keys.
- Return type:
Iterator[_Col]
- iter_cols()¶
Iterate cols.
- Return type:
ItemsView[_Col, dict[_Row, AnyValue]]
- iter_row(row, sparse=False)¶
Iterate row _Row elements.
- Parameters:
row (_Row)
sparse (bool)
- Return type:
Iterator[tuple[_Col, AnyValue]]
- iter_row_keys()¶
Return row keys.
- Return type:
Iterator[_Row]
- iter_rows()¶
Iterate rows.
- Return type:
ItemsView[_Row, dict[_Col, AnyValue]]
- remove_col(col)¶
Remove column col.
- Parameters:
col (_Col)
- Return type:
None
- remove_row(row)¶
Remove row _Row.
- Parameters:
row (_Row)
- Return type:
None
- row(idx)¶
Return row.
- Parameters:
idx (_Row)
- Return type:
dict[_Col, AnyValue]
- row_size()¶
Return the number of rows.
- Return type:
int
- transpose()¶
Transpose matrix.
- Return type:
AbstractMatrix[_Col, _Row, AnyValue]
- class interregnum.bidimensional.matrix.Matrix(default_value_f, row_keys, col_keys)¶
Bases:
TransposableMatrix[_Row,_Col,AnyValue]Dict based matrix.
- Parameters:
default_value_f (Callable[[_Row, _Col], AnyValue])
row_keys (Iterable[_Row])
col_keys (Iterable[_Col])
- transpose()¶
Return a transposed matrix from this one.
- Return type:
TransposableMatrix[_Col, _Row, AnyValue]
- class interregnum.bidimensional.matrix.TransposableMatrix¶
Bases:
AbstractMatrix[_Row,_Col,AnyValue]A matrix that can be transposed.
- transpose()¶
Return a transposed matrix from this one.
- Return type:
TransposableMatrix[_Col, _Row, AnyValue]
- class interregnum.bidimensional.matrix.TransposedMatrix(matrix)¶
Bases:
TransposableMatrix[_Row,_Col,AnyValue]Transposed view of a matrix.
- Parameters:
matrix (TransposableMatrix[_Col, _Row, AnyValue])
- transpose()¶
Return a transposed matrix from this one.
- Return type:
TransposableMatrix[_Col, _Row, AnyValue]
interregnum.bidimensional.sparse module¶
A sparse bi-dimensional table.
- class interregnum.bidimensional.sparse.SparseTable(default)¶
Bases:
Bidimensional[_Row,_Col,AnyValue]Bi-dimensional table which initialises missing values.
Rows and cols keys are added dynamically.
Create a sparse table with a default value for empty cells.
- Parameters:
default (AnyValue)
- __getitem__(idx)¶
Return the element at idx.
- Parameters:
idx (tuple[_Row, _Col]) – a row-column tuple
- Returns:
the element at idx
>>> t = SparseTable(0)
>>> a = t[0, 3]
- Return type:
AnyValue
- __str__()¶
Return str(self).
- Return type:
str
- col_size()¶
Return the number of columns.
- Return type:
int
- empty()¶
Return True if the object is empty.
- Return type:
bool
- iter_col(col, sparse=False)¶
Iterate existing elements in a column.
If an element does not exist and not sparse, yield default value
- Parameters:
col (_Col) – column index
sparse (bool) – if True, return only non-default values
SparseTable(0) (>>> t =)
t[2 (>>>)
1 (3] =)
t[5 (>>>)
2 (3] =)
t.iter_col(3) (>>> for x in)
print(x) (>>>)
- Return type:
Iterator[tuple[_Row, AnyValue]]
- iter_col_keys()¶
Return keys from existing columns.
>>> t = SparseTable(0) >>> t['Alice', 'Bob'] = 5 >>> t['Bob', 'Charles'] = 3 >>> # 'Bob', 'Charles' >>> print(t.col_keys())
- Return type:
Iterator[_Col]
- iter_row(row, sparse=False)¶
Iterate row _Row elements.
- Parameters:
row (_Row)
sparse (bool)
- Return type:
Iterator[tuple[_Col, AnyValue]]
- iter_row_keys()¶
Iterate row keys.
- Return type:
Iterator[_Row]
- keys()¶
Return different existing keys in table.
>>> t = SparseTable(0) >>> t['Alice', 'Bob'] = 5 >>> t['Bob', 'Charles'] = 3 >>> # 'Alice', 'Bob', 'Charles' >>> print(t.keys())
- Return type:
Iterator[_Row | _Col]
- remove_col(col)¶
Remove elements from col.
- Parameters:
col (_Col)
- Return type:
None
- remove_row(row)¶
Remove elements from row.
- Parameters:
row (_Row)
- Return type:
None
- row(idx)¶
Get items in row (non-empty columns).
- Parameters:
idx (_Row) – row index
- Returns:
row at idx
>>> t = SparseTable(0)
>>> t[5, 2] = 2
>>> r5 = t.row(5)
- Return type:
dict[_Col, AnyValue]
- row_keys()¶
Return keys from existing rows.
>>> t = SparseTable(0) >>> t['Alice', 'Bob'] = 5 >>> t['Bob', 'Charles'] = 3 >>> # 'Alice', 'Bob' >>> print(t.row_keys())
- Return type:
KeysView[_Row]
- row_size()¶
Return the number of rows.
- Return type:
int
- rows()¶
Iterate existing rows.
- Returns:
iterator of (row key, row defaultdict)
- Return type:
ItemsView[_Row, dict[_Col, AnyValue]]