fips.Space.from_index#

classmethod Space.from_index(index)[source]#

Build the space an index with a block level describes.

Each block gets the levels it has labels on; a level that is missing (NaN) on every row of a block is padding and is dropped. A block’s labels keep the order of its rows in index, and the blocks the order in which they first appear. The levels keep their order in index.

Parameters:

index (Index) – Labels with a block level, such as index or the index of a Vector.

Returns:

The space whose blocks the index holds.

Return type:

Space

Raises:

ValueError – If index has no block level, a row has no block name, a block has no other level, or a block has labels on a level for some of its rows and not for others.

Examples

>>> import pandas as pd
>>> from fips import Space
>>> index = pd.MultiIndex.from_tuples(
...     [("flux", 1.0, None), ("flux", 2.0, None), ("bias", None, "A")],
...     names=["block", "cell", "site"],
... )
>>> Space.from_index(index).select("bias").tolist()
['A']