renumics.spotlight.dataset¶
dataset
¶
This module provides Spotlight dataset.
Dataset
¶
Spotlight dataset.
open
¶
open(mode: str | None = None) -> None
Open previously closed file or reopen file with another mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str | None
|
Optional open mode. If not given, use |
None
|
iterrows
¶
iterrows() -> Iterable[dict[str, OutputType | None]]
iterrows(
column_names: str | Iterable[str],
) -> (
Iterable[dict[str, OutputType | None]]
| Iterable[OutputType | None]
)
iterrows(
column_names: str | Iterable[str] | None = None,
) -> (
Iterable[dict[str, OutputType | None]]
| Iterable[OutputType | None]
)
Iterate through dataset rows.
from_pandas
¶
from_pandas(
df: DataFrame,
index: bool = False,
dtypes: dict[str, Any] | None = None,
workdir: PathType | None = None,
) -> None
Import a pandas dataframe to the dataset.
Only scalar types supported by the Spotlight dataset are imported, the other are printed in a warning message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
|
required |
index
|
bool
|
Whether to import index of the dataframe as regular dataset column. |
False
|
dtypes
|
dict[str, Any] | None
|
Optional dict with mapping |
None
|
workdir
|
PathType | None
|
Optional folder where audio/images/meshes are stored. If
|
None
|
Example
from datetime import datetime import pandas as pd from renumics.spotlight import Dataset df = pd.DataFrame( ... { ... "bools": [True, False, False], ... "ints": [-1, 0, 1], ... "floats": [-1.0, 0.0, 1.0], ... "strings": ["a", "b", "c"], ... "datetimes": datetime.now().astimezone(), ... } ... ) with Dataset("docs/example.h5", "w") as dataset: ... dataset.from_pandas(df, index=False) with Dataset("docs/example.h5", "r") as dataset: ... print(len(dataset)) ... print(sorted(dataset.keys())) 3 ['bools', 'datetimes', 'floats', 'ints', 'strings']
from_csv
¶
from_csv(
filepath: PathType,
dtypes: dict[str, Any] | None = None,
columns: Iterable[str] | None = None,
workdir: PathType | None = None,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
PathType
|
Path of csv file to read. |
required |
dtypes
|
dict[str, Any] | None
|
Optional dict with mapping |
None
|
columns
|
Iterable[str] | None
|
Optional columns to read from csv. If not set, read all columns. |
None
|
workdir
|
PathType | None
|
Optional folder where audio/images/meshes are stored. If
|
None
|
to_pandas
¶
to_pandas() -> DataFrame
Export the dataset to pandas dataframe.
Only scalar types of the Spotlight dataset are exported, the others are printed in a warning message.
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Example
import pandas as pd from renumics.spotlight import Dataset with Dataset("docs/example.h5", "w") as dataset: ... dataset.append_bool_column("bools", [True, False, False]) ... dataset.append_int_column("ints", [-1, 0, 1]) ... dataset.append_float_column("floats", [-1.0, 0.0, 1.0]) ... dataset.append_string_column("strings", ["a", "b", "c"]) ... dataset.append_datetime_column("datetimes", optional=True) with Dataset("docs/example.h5", "r") as dataset: ... df = dataset.to_pandas() print(len(df)) 3 print(df.columns.sort_values()) Index(['bools', 'datetimes', 'floats', 'ints', 'strings'], dtype='object')
append_bool_column
¶
append_bool_column(
name: str,
values: BoolColumnInputType
| Iterable[BoolColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: BoolColumnInputType = False,
description: str | None = None,
tags: list[str] | None = None,
editable: bool = True,
) -> None
Create and optionally fill a boolean column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
BoolColumnInputType | Iterable[BoolColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. |
False
|
default
|
BoolColumnInputType
|
Value to use by default if column is optional and no value
or |
False
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
editable
|
bool
|
Whether column is editable in Spotlight. |
True
|
Example
from renumics.spotlight import Dataset value = False with Dataset("docs/example.h5", "w") as dataset: ... dataset.append_bool_column("bool_values", 5*[value]) with Dataset("docs/example.h5", "r") as dataset: ... print(dataset["bool_values", 2]) False
append_int_column
¶
append_int_column(
name: str,
values: IntColumnInputType
| Iterable[IntColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: IntColumnInputType = -1,
description: str | None = None,
tags: list[str] | None = None,
editable: bool = True,
) -> None
Create and optionally fill an integer column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
IntColumnInputType | Iterable[IntColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. |
False
|
default
|
IntColumnInputType
|
Value to use by default if column is optional and no value
or |
-1
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
editable
|
bool
|
Whether column is editable in Spotlight. |
True
|
Example
Find a similar example usage in
renumics.spotlight.dataset.Dataset.append_bool_column.
append_float_column
¶
append_float_column(
name: str,
values: FloatColumnInputType
| Iterable[FloatColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: FloatColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
editable: bool = True,
) -> None
Create and optionally fill a float column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
FloatColumnInputType | Iterable[FloatColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
FloatColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
editable
|
bool
|
Whether column is editable in Spotlight. |
True
|
Example
Find a similar example usage in
renumics.spotlight.dataset.Dataset.append_bool_column.
append_string_column
¶
append_string_column(
name: str,
values: StringColumnInputType
| Iterable[StringColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: str | None = None,
description: str | None = None,
tags: list[str] | None = None,
editable: bool = True,
) -> None
Create and optionally fill a float column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
StringColumnInputType | Iterable[StringColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
str | None
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
editable
|
bool
|
Whether column is editable in Spotlight. |
True
|
Example
Find a similar example usage in
renumics.spotlight.dataset.Dataset.append_bool_column.
append_datetime_column
¶
append_datetime_column(
name: str,
values: DatetimeColumnInputType
| Iterable[DatetimeColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: DatetimeColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
) -> None
Create and optionally fill a datetime column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
DatetimeColumnInputType | Iterable[DatetimeColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
DatetimeColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
Example
import numpy as np import datetime from renumics.spotlight import Dataset date = datetime.datetime.now() with Dataset("docs/example.h5", "w") as dataset: ... dataset.append_datetime_column("dates", 5*[date]) with Dataset("docs/example.h5", "r") as dataset: ... print(dataset["dates", 2] < datetime.datetime.now()) True
append_array_column
¶
append_array_column(
name: str,
values: ArrayColumnInputType
| Iterable[ArrayColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: ArrayColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
) -> None
Create and optionally fill a numpy array column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
ArrayColumnInputType | Iterable[ArrayColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
ArrayColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
Example
import numpy as np from renumics.spotlight import Dataset array_data = np.random.rand(5,3) with Dataset("docs/example.h5", "w") as dataset: ... dataset.append_array_column("arrays", 5*[array_data]) with Dataset("docs/example.h5", "r") as dataset: ... print(dataset["arrays", 2].shape) (5, 3)
append_categorical_column
¶
append_categorical_column(
name: str,
values: CategoricalColumnInputType
| Iterable[CategoricalColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: str | None = None,
description: str | None = None,
tags: list[str] | None = None,
editable: bool = True,
categories: Iterable[str]
| dict[str, int]
| None = None,
) -> None
Create and optionally fill a categorical column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
categories
|
Iterable[str] | dict[str, int] | None
|
The allowed categories for this column ("" is not allowed) |
None
|
values
|
CategoricalColumnInputType | Iterable[CategoricalColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
str | None
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
editable
|
bool
|
Whether column is editable in Spotlight. |
True
|
Example
Find an example usage in renumics.spotlight.dtypes.Category.
append_embedding_column
¶
append_embedding_column(
name: str,
values: EmbeddingColumnInputType
| Iterable[EmbeddingColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: EmbeddingColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
length: int | None = None,
dtype: str | dtype = "float32",
) -> None
Create and optionally fill a mesh column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
EmbeddingColumnInputType | Iterable[EmbeddingColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
EmbeddingColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
dtype
|
str | dtype
|
A valid float numpy dtype. Default is "float32". |
'float32'
|
Example
Find an example usage in renumics.spotlight.dtypes.Embedding.
append_sequence_1d_column
¶
append_sequence_1d_column(
name: str,
values: Sequence1DColumnInputType
| Iterable[Sequence1DColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: Sequence1DColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
x_label: str | None = None,
y_label: str | None = None,
) -> None
Create and optionally fill a 1d-sequence column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
Sequence1DColumnInputType | Iterable[Sequence1DColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
Sequence1DColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
x_label
|
str | None
|
Optional x-axis label. |
None
|
y_label
|
str | None
|
Optional y-axis label. If |
None
|
Example
Find an example usage in renumics.spotlight.dtypes.Sequence1D.
append_mesh_column
¶
append_mesh_column(
name: str,
values: MeshColumnInputType
| Iterable[MeshColumnInputType | None]
| None = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: MeshColumnInputType | None = None,
description: str | None = None,
tags: list[str] | None = None,
lookup: BoolType
| Iterable[MeshColumnInputType]
| dict[str, MeshColumnInputType]
| None = None,
external: bool = False,
) -> None
Create and optionally fill a mesh column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
MeshColumnInputType | Iterable[MeshColumnInputType | None] | None
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
MeshColumnInputType | None
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
lookup
|
BoolType | Iterable[MeshColumnInputType] | dict[str, MeshColumnInputType] | None
|
Optional data lookup/flag for automatic lookup creation.
If |
None
|
external
|
bool
|
Whether column should only contain paths/URLs to data and load it on demand. |
False
|
Example
Find an example usage in renumics.spotlight.dtypes.Mesh.
append_image_column
¶
append_image_column(
name: str,
values: ImageColumnInputType
| Iterable[ImageColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: ImageColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
lookup: BoolType
| Iterable[MeshColumnInputType]
| dict[str, MeshColumnInputType]
| None = None,
external: bool = False,
) -> None
Create and optionally fill an image column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
ImageColumnInputType | Iterable[ImageColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
ImageColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
lookup
|
BoolType | Iterable[MeshColumnInputType] | dict[str, MeshColumnInputType] | None
|
Optional data lookup/flag for automatic lookup creation.
If |
None
|
external
|
bool
|
Whether column should only contain paths/URLs to data and load it on demand. |
False
|
Example
Find an example usage in renumics.spotlight.dtypes.Image.
append_audio_column
¶
append_audio_column(
name: str,
values: AudioColumnInputType
| Iterable[AudioColumnInputType]
| None = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: ImageColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
lookup: BoolType
| Iterable[MeshColumnInputType]
| dict[str, MeshColumnInputType]
| None = None,
external: bool = False,
lossy: bool | None = None,
) -> None
Create and optionally fill an audio column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
AudioColumnInputType | Iterable[AudioColumnInputType] | None
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
ImageColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
lookup
|
BoolType | Iterable[MeshColumnInputType] | dict[str, MeshColumnInputType] | None
|
Optional data lookup/flag for automatic lookup creation.
If |
None
|
external
|
bool
|
Whether column should only contain paths/URLs to data and load it on demand. |
False
|
lossy
|
bool | None
|
Whether to store data lossy or lossless (default if
|
None
|
Example
Find an example usage in renumics.spotlight.media.Audio.
append_video_column
¶
append_video_column(
name: str,
values: VideoColumnInputType
| Iterable[VideoColumnInputType]
| None = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: VideoColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
lookup: BoolType
| Iterable[MeshColumnInputType]
| dict[str, MeshColumnInputType]
| None = None,
external: bool = False,
) -> None
Create and optionally fill an video column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
VideoColumnInputType | Iterable[VideoColumnInputType] | None
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
VideoColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
lookup
|
BoolType | Iterable[MeshColumnInputType] | dict[str, MeshColumnInputType] | None
|
Optional data lookup/flag for automatic lookup creation.
If |
None
|
external
|
bool
|
Whether column should only contain paths/URLs to data and load it on demand. |
False
|
append_window_column
¶
append_window_column(
name: str,
values: WindowColumnInputType
| Iterable[WindowColumnInputType]
| None = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: WindowColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
editable: bool = True,
) -> None
Create and optionally fill window column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
WindowColumnInputType | Iterable[WindowColumnInputType] | None
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
WindowColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
editable
|
bool
|
Whether column is editable in Spotlight. |
True
|
Example
Find an example usage in renumics.spotlight.dtypes.Window.
append_bounding_box_column
¶
append_bounding_box_column(
name: str,
values: BoundingBoxColumnInputType
| Iterable[BoundingBoxColumnInputType]
| None = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: BoundingBoxColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
editable: bool = True,
) -> None
Create and optionally fill axis-aligned bounding box column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
values
|
BoundingBoxColumnInputType | Iterable[BoundingBoxColumnInputType] | None
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
BoundingBoxColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
editable
|
bool
|
Whether column is editable in Spotlight. |
True
|
append_column
¶
append_column(
name: str,
dtype: Any,
values: ColumnInputType
| Iterable[ColumnInputType] = None,
order: int | None = None,
hidden: bool = False,
optional: bool = False,
default: ColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
**attrs: Any,
) -> None
Create and optionally fill a dataset column of the given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
dtype
|
Any
|
Column type. |
required |
values
|
ColumnInputType | Iterable[ColumnInputType]
|
Optional column values. If a single value, the whole column filled with this value. |
None
|
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool
|
Whether column is hidden in Spotlight. |
False
|
optional
|
bool
|
Whether column is optional. If |
False
|
default
|
ColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
attrs
|
Any
|
Optional arguments for the respective append column method. |
{}
|
Example
>>> from renumics.spotlight import Dataset
>>> with Dataset("docs/example.h5", "w") as dataset:
... dataset.append_column("int", int, range(5))
... dataset.append_column("float", float, 1.0)
... dataset.append_column("bool", bool, True)
>>> with Dataset("docs/example.h5", "r") as dataset:
... print(len(dataset))
... print(sorted(dataset.keys()))
5
['bool', 'float', 'int']
>>> with Dataset("docs/example.h5", "r") as dataset:
... print(dataset["int"])
... print(dataset["bool"])
... print(dataset["float"])
[0 1 2 3 4]
[ True True True True True]
[1. 1. 1. 1. 1.]
append_row
¶
append_row(**values: ColumnInputType) -> None
Append a row to the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ColumnInputType
|
A mapping column name -> value. Keys of |
{}
|
Example
from renumics.spotlight import Dataset with Dataset("docs/example.h5", "w") as dataset: ... dataset.append_bool_column("bool_values") ... dataset.append_float_column("float_values") data = {"bool_values":True, "float_values":0.2} with Dataset("docs/example.h5", "a") as dataset: ... dataset.append_row(data) ... dataset.append_row(data) ... print(dataset["float_values", 1]) 0.2
append_dataset
¶
append_dataset(dataset: Dataset) -> None
Append a dataset to the current dataset row-wise.
insert_row
¶
insert_row(
index: IndexType, values: dict[str, ColumnInputType]
) -> None
Insert a row into the dataset at the given index.
Example
>>> from renumics.spotlight import Dataset
>>> with Dataset("example.h5", "w") as dataset:
... dataset.append_float_column("floats", [-1.0, 0.0, 1.0])
... dataset.append_int_column("ints", [-1, 0, 2])
... print(len(dataset))
... print(dataset["floats"])
... print(dataset["ints"])
3
[-1. 0. 1.]
[-1 0 2]
>>> with Dataset("example.h5", "a") as dataset:
... dataset.insert_row(2, {"floats": float("nan"), "ints": 1000})
... dataset.insert_row(-3, {"floats": 3.14, "ints": -1000})
... print(len(dataset))
... print(dataset["floats"])
... print(dataset["ints"])
5
[-1. 3.14 0. nan 1. ]
[ -1 -1000 0 1000 2]
pop
¶
pop(item: str) -> ndarray
pop(item: IndexType) -> dict[str, OutputType | None]
pop(
item: str | IndexType,
) -> ndarray | dict[str, OutputType | None]
Delete a dataset column or row and return it.
isnull
¶
isnull(column_name: str) -> ndarray
Get missing values mask for the given column.
None, NaN and category "" values are mapped to True. So null-mask
for columns of type bool, int and string always has only False values.
A Window is mapped on True only if both start and end are NaN.
notnull
¶
notnull(column_name: str) -> ndarray
Get non-missing values mask for the given column.
None, NaN and category "" values are mapped to False. So non-null-mask
for columns of type bool, int and string always has only True values.
A Window is mapped on True if at least one of its values is not NaN.
rebuild
¶
rebuild() -> None
Update old-style columns in the dataset.
Be aware, that it can take some time and memory. It is useful to do
prune after rebuild.
prune
¶
prune() -> None
Rebuild the whole dataset with the same content.
This method can be useful after column deletions, in order to decrease the dataset file size.
get_dtype
¶
get_dtype(column_name: str) -> DType
Get type of dataset column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column_name
|
str
|
Column name. |
required |
Example
from renumics.spotlight import Dataset with Dataset("docs/example.h5", "w") as dataset: ... dataset.append_bool_column("bool") ... dataset.append_datetime_column("datetime") ... dataset.append_array_column("array") ... dataset.append_mesh_column("mesh") with Dataset("docs/example.h5", "r") as dataset: ... for column_name in sorted(dataset.keys()): ... print(column_name, dataset.get_dtype(column_name)) array array bool bool datetime datetime mesh Mesh
get_column_attributes
¶
get_column_attributes(name: str) -> dict[str, Any]
Get attributes of a column. Available but unset attributes contain None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
Example
from renumics.spotlight import Dataset with Dataset("docs/example.h5", "w") as dataset: ... dataset.append_int_column("int", range(5)) ... dataset.append_int_column( ... "int1", ... hidden=True, ... default=10, ... description="integer column", ... tags=["important"], ... editable=False, ... ) with Dataset("docs/example.h5", "r") as dataset: ... attributes = dataset.get_column_attributes("int") ... for key in sorted(attributes.keys()): ... print(key, attributes[key]) default -1 description None editable True hidden False optional True order None tags None with Dataset("docs/example.h5", "r") as dataset: ... attributes = dataset.get_column_attributes("int1") ... for key in sorted(attributes.keys()): ... print(key, attributes[key]) default 10 description integer column editable False hidden True optional True order None tags ['important']
set_column_attributes
¶
set_column_attributes(
name: str,
order: int | None = None,
hidden: bool | None = None,
optional: bool | None = None,
default: ColumnInputType = None,
description: str | None = None,
tags: list[str] | None = None,
**attrs: Any,
) -> None
Set attributes of a column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Column name. |
required |
order
|
int | None
|
Optional Spotlight priority order value. |
None
|
hidden
|
bool | None
|
Whether column is hidden in Spotlight. |
None
|
optional
|
bool | None
|
Whether column is optional. If |
None
|
default
|
ColumnInputType
|
Value to use by default if column is optional and no value
or |
None
|
description
|
str | None
|
Optional column description. |
None
|
tags
|
list[str] | None
|
Optional tags for the column. |
None
|
attrs
|
Any
|
Optional more DType specific attributes . |
{}
|
unescape_dataset_name
¶
unescape_dataset_name(escaped_name: str) -> str
Replace "\" with "\" and "\s" with "/".