fips.Space#
- class fips.Space(blocks, levels=None)[source]#
An ordered set of named blocks, each labeled by its own pandas index.
A space labels a state vector, the observations, or one axis of a matrix. Each block keeps the index it was given, with its own levels and dtypes;
indexputs them together as onepandas.MultiIndexwith ablocklevel first. A level that one block has and another does not is missing (NaN) on the other block’s rows. The labels are never changed: they are not converted to numbers and not rounded (seeround_labels()).- Parameters:
blocks (
Mapping[str,Index]) – The blocks in order, each name mapped to its labels. A name that is not a string is converted to one. Every level must be named, no level may be calledblock, and a block’s labels must be unique and not missing.levels (
Sequence[Hashable] |None) – The order of the levels afterblockinindex: every level of every block, once. By default, the order in which they first appear.
- Raises:
ValueError – If two blocks have the same name, a block has no labels, an unnamed level, a
blocklevel, a missing label or a label twice, or levels does not name each level once.
See also
VectorValues on a space.
Examples
>>> import pandas as pd >>> from fips import Space >>> space = Space( ... { ... "flux": pd.Index([1, 2], name="cell"), ... "bias": pd.Index(["A"], name="site"), ... } ... ) >>> space.index MultiIndex([('flux', 1.0, nan), ('flux', 2.0, nan), ('bias', nan, 'A')], names=['block', 'cell', 'site'])
The padding shows
cellas floats, but the level keeps its integers, and a block comes back as it was given:>>> space.index.levels[1] Index([1, 2], dtype='int64', name='cell') >>> space.select("flux") Index([1, 2], dtype='int64', name='cell') >>> space.slice("bias") slice(2, 3, None)
Attributes
The labels of every block as one MultiIndex, with the |
|
The names of the levels after |
|
The names of the blocks, in order. |
|
Where each block starts in |
Methods
|
Return where each label of this space is in other: an exact join. |
|
Build the space an index with a |
|
Return the space with every float level rounded to decimals places. |
|
Return the labels of block, as the block was given. |
|
Return the positions of block in |