Tables API reference¶
For the on-disk format of each table type, see the Table Specifications.
Opening tables¶
ngio.tables.open_table
¶
open_table(
store: StoreOrGroup,
backend: TableBackend | None = None,
cache: bool = False,
mode: AccessModeLiteral = "r+",
) -> Table
Open a table from a Zarr store.
Source code in src/ngio/tables/_tables_container.py
ngio.tables.open_table_as
¶
open_table_as(
store: StoreOrGroup,
table_cls: type[TableType],
backend: TableBackend | None = None,
cache: bool = False,
mode: AccessModeLiteral = "r+",
) -> TableType
Open a table from a Zarr store as a specific type.
Source code in src/ngio/tables/_tables_container.py
ngio.tables.open_tables_container
¶
open_tables_container(
store: StoreOrGroup,
cache: bool = False,
mode: AccessModeLiteral = "r+",
) -> TablesContainer
Open a table handler from a Zarr store.
Source code in src/ngio/tables/_tables_container.py
Tables container¶
ngio.tables.TablesContainer
¶
TablesContainer(group_handler: ZarrGroupHandler)
A class to handle the /tables group in an OME-NGFF file.
Initialize the TablesContainer.
Source code in src/ngio/tables/_tables_container.py
list
¶
list(
filter_types: TypedTable | str | None = None,
) -> list[str]
List all tables in the group.
Parameters:
-
filter_types(TypedTable | str | None, default:None) –If provided, only return tables of this type.
Returns:
-
list[str]–A list of table names.
Source code in src/ngio/tables/_tables_container.py
get
¶
get(
name: str,
backend: TableBackend | None = None,
strict: bool = True,
) -> Table
Get a table from the group.
Parameters:
-
name(str) –The name of the table.
-
backend(TableBackend | None, default:None) –The backend to use for reading the table.
-
strict(bool, default:True) –If True, raise an error if the table type is not implemented.
Returns:
-
Table–The table object.
Source code in src/ngio/tables/_tables_container.py
get_as
¶
get_as(
name: str,
table_cls: type[TableType],
backend: TableBackend | None = None,
) -> TableType
Get a table from the group as a specific type.
Parameters:
-
name(str) –The name of the table.
-
table_cls(type[TableType]) –The table class to use for loading the table.
-
backend(TableBackend | None, default:None) –The backend to use for reading the table.
Returns:
-
TableType–The table object of the specified type.
Source code in src/ngio/tables/_tables_container.py
delete
¶
Delete a table from the group.
Parameters:
-
name(str) –The name of the table to delete.
-
missing_ok(bool, default:False) –If True, do not raise an error if the table does not exist.
Source code in src/ngio/tables/_tables_container.py
add
¶
add(
name: str,
table: Table,
backend: TableBackend | None = None,
overwrite: bool = False,
) -> None
Add a table to the group.
Parameters:
-
name(str) –The name of the table.
-
table(Table) –The table object to add.
-
backend(TableBackend | None, default:None) –The backend to use for writing the table. If
None(default), the table's own backend is preserved. -
overwrite(bool, default:False) –Whether to overwrite an existing table with the same name.
Source code in src/ngio/tables/_tables_container.py
Table types¶
ROI tables¶
Feature tables¶
Condition tables¶
Generic tables¶
ngio.tables.GenericTable
¶
Bases: AbstractBaseTable
Class to a non-specific table.
This can be used to load any table that does not have a specific definition.
Initialize the table.
Source code in src/ngio/tables/_abstract_table.py
backend_name
property
¶
Return the name of the backend.
If no backend is attached yet, the backend name stored in the table metadata is returned.
load_as_anndata
¶
Load the table as an AnnData object.
load_as_pandas_df
¶
Load the table as a pandas DataFrame.
load_as_polars_lf
¶
Load the table as a polars LazyFrame.
set_table_data
¶
Set the table.
If an object is passed, it will be used as the table. If None is passed, the table will be loaded from the backend.
If refresh is True, the table will be reloaded from the backend. If table is not None, this will be ignored.
Source code in src/ngio/tables/_abstract_table.py
set_backend
¶
set_backend(
handler: ZarrGroupHandler | None = None,
backend: TableBackend | None = None,
) -> None
Set the backend of the table.
If backend is None, the backend stored in the table metadata
is used.
If no handler is provided and the table is not yet attached to a
Zarr group, a string backend is only recorded as the table's
preferred backend; the backend is instantiated when the table is
written (e.g. by add_table).
Source code in src/ngio/tables/_abstract_table.py
from_table_data
classmethod
¶
Create a new ROI table from a Zarr group handler.
consolidate
¶
Write the current state of the table to the Zarr file.
Source code in src/ngio/tables/_abstract_table.py
table_type
staticmethod
¶
version
staticmethod
¶
from_handler
classmethod
¶
from_handler(
handler: ZarrGroupHandler,
backend: TableBackend | None = None,
) -> GenericTable
Backends¶
ngio.tables.TableBackend
module-attribute
¶
TableBackend = (
Literal["anndata", "json", "csv", "parquet"]
| str
| TableBackendProtocol
)
ngio.tables.ImplementedTableBackends
¶
A class to manage the available table backends.
normalize_backend_name
¶
Resolve a backend name or alias to its canonical name.
Raises:
-
NgioValueError–If the backend name is not implemented.
Source code in src/ngio/tables/backends/_table_backends.py
get_backend
¶
get_backend(
*,
group_handler: ZarrGroupHandler,
backend_name: str,
index_key: str | None = None,
index_type: Literal["int", "str"] | None = None,
) -> TableBackendProtocol
Instantiate the named backend and attach it to group_handler.
Raises:
-
NgioValueError–If
backend_nameis not registered.
Source code in src/ngio/tables/backends/_table_backends.py
add_backend
¶
add_backend(
table_backend: type[TableBackendProtocol],
overwrite: bool = False,
aliases: list[str] | None = None,
) -> None
Register a new handler.