Types
timenet.types ¶source
TimeF value types and type system: versions, units, enums, specs, annotations, tasks, metadata.
ANNOTATION_BASES
module-attribute
¶source
ANNOTATION_BASES: dict[AnnotationType, type[Annotation]] = {
AnnotationType.STATIC: StaticAnnotation,
AnnotationType.POINT: PointAnnotation,
AnnotationType.INTERVAL: IntervalAnnotation,
}
Annotation
dataclass
¶source
Base for all annotations. Not instantiated directly; use one of the three shapes below.
description
class-attribute
instance-attribute
¶source
description: str | None = None
Optional human-readable description of the annotation.
unit
class-attribute
instance-attribute
¶source
unit: str | Unit | None = None
Optional physical unit of value — a unit string (e.g. "years") or a :class:pint.Unit.
Validated against the shared registry on construction; an unrecognized string raises ValueError,
and a pint.Unit is stored as its canonical name.
AnnotationDescriptor
dataclass
¶source
Type-level projection of an annotation key, stored in the schema and manifest.
annotation_type
instance-attribute
¶source
annotation_type: AnnotationType
Which of the three annotation shapes this key uses.
description
class-attribute
instance-attribute
¶source
description: str | None = None
Optional human-readable description of the annotation.
AnnotationType ¶source
Bases: StrEnum
The three annotation shapes; the discriminator stored on disk and in the manifest.
CaptioningTask
dataclass
¶source
Bases: TargetTask
Free-form text describing the sample (the target is the caption).
sample_ids
class-attribute
instance-attribute
¶source
Ids of the samples this task targets, populated by add_task.
ClassificationTask
dataclass
¶source
Bases: TargetTask
One discrete label applied to the whole sample (the target).
sample_ids
class-attribute
instance-attribute
¶source
Ids of the samples this task targets, populated by add_task.
target
instance-attribute
¶source
target: str
The supervised target: the class label, region label, answer, or caption for the sample.
DataSource
dataclass
¶source
DatasetMetadata
dataclass
¶source
A dataset's descriptive identity: who it is, not what it emits.
Authored in the dataset card. dataset_version is the upstream source's semantic version;
yaml_schema_version is the card's own field-schema version. dataset_id is an org/name
pair (HuggingFace style, exactly one slash); ids are case-sensitive, so avoid casing-only
differences on case-insensitive filesystems.
dataset_id
instance-attribute
¶source
dataset_id: str
HuggingFace-style org/name pair; case-sensitive, exactly one slash.
dataset_version
instance-attribute
¶source
dataset_version: Version
Semantic version of the upstream source data.
license
instance-attribute
¶source
license: License
Legal license of the source data, as an SPDX-style identifier.
source_url
class-attribute
instance-attribute
¶source
source_url: str | None = None
Link to the dataset's origin, if any.
yaml_schema_version
class-attribute
instance-attribute
¶source
yaml_schema_version: int = 1
Version of the card's own field schema.
from_dict
classmethod
¶source
from_dict(data: dict[str, Any]) -> DatasetMetadata
Build metadata from a plain mapping of card fields.
Enum and version fields arrive as strings (license, domains, dataset_version) and are
coerced here; unmodeled keys are ignored. Shared by :meth:from_yaml and the manifest codec so
the mapping lives in one place. Coercion may raise KeyError (missing field) or ValueError
(bad license/domain/version/id); callers wrap these in their own error type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
A mapping with the card fields (strings for the enums and the version). |
required |
Returns:
| Type | Description |
|---|---|
DatasetMetadata
|
The constructed :class: |
from_yaml
classmethod
¶source
from_yaml(path: str | Path) -> DatasetMetadata
Load and validate a dataset card YAML into metadata.
The card is validated against the packaged dataset-card.schema.json (so authoring mistakes
surface with clear, aggregated messages) before construction. PyYAML and jsonschema are optional
and imported lazily; install the timenet[curation] extra to use this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the card YAML file. |
required |
Returns:
| Type | Description |
|---|---|
DatasetMetadata
|
The constructed :class: |
Raises:
| Type | Description |
|---|---|
InvalidCardError
|
If the curation extra is missing, or the card is unreadable, is not a mapping, fails schema validation, or has an invalid field value. |
DatasetSchema
dataclass
¶source
A dataset's type declaration, derived from its data (never hand-authored).
Holds flat descriptor instances for specs / data sources / annotations, and the real built-in
:class:~timenet.types.tasks.Task subclasses (resolved against the registry, not reconstructed).
annotations
class-attribute
instance-attribute
¶source
annotations: tuple[AnnotationDescriptor, ...] = ()
Type-level descriptors for the dataset's annotation keys.
data_sources
class-attribute
instance-attribute
¶source
data_sources: tuple[DataSource, ...] = ()
Origins that produced the modalities, keyed by data_source_type.
tasks
class-attribute
instance-attribute
¶source
Built-in Task subclasses the dataset declares, resolved from the registry.
time_series_specs
class-attribute
instance-attribute
¶source
time_series_specs: tuple[TimeSeriesSpec, ...] = ()
Descriptors for the dataset's measurement modalities.
Domain ¶source
ForecastingTask
dataclass
¶source
Bases: Task
Predict future values of a series, conditioned on context samples (no scalar target).
sample_ids
class-attribute
instance-attribute
¶source
Ids of the samples this task targets, populated by add_task.
IntervalAnnotation
dataclass
¶source
Bases: Annotation
Anchored to a bounded interval in the original recording timeline.
description
class-attribute
instance-attribute
¶source
description: str | None = None
Optional human-readable description of the annotation.
end_time_s
instance-attribute
¶source
end_time_s: float
Interval end in seconds; must exceed start_time_s.
start_time_s
instance-attribute
¶source
start_time_s: float
Interval start on the recording timeline, in seconds.
time_series_ids
class-attribute
instance-attribute
¶source
Series this annotation targets; None covers the whole sample.
unit
class-attribute
instance-attribute
¶source
unit: str | Unit | None = None
Optional physical unit of value — a unit string (e.g. "years") or a :class:pint.Unit.
Validated against the shared registry on construction; an unrecognized string raises ValueError,
and a pint.Unit is stored as its canonical name.
LabelingTask
dataclass
¶source
Bases: TargetTask
Time-localized labels within a sample, optionally targeting specific series and windows.
sample_ids
class-attribute
instance-attribute
¶source
Ids of the samples this task targets, populated by add_task.
target
instance-attribute
¶source
target: str
The supervised target: the class label, region label, answer, or caption for the sample.
target_schema
class-attribute
instance-attribute
¶source
target_schema: str | None = None
Name of the label vocabulary the target belongs to.
License ¶source
PointAnnotation
dataclass
¶source
Bases: Annotation
Anchored to a single instant in the original recording timeline.
description
class-attribute
instance-attribute
¶source
description: str | None = None
Optional human-readable description of the annotation.
start_time_s
instance-attribute
¶source
start_time_s: float
Instant on the original recording timeline, in seconds.
time_series_ids
class-attribute
instance-attribute
¶source
Series this annotation targets; None covers the whole sample.
unit
class-attribute
instance-attribute
¶source
unit: str | Unit | None = None
Optional physical unit of value — a unit string (e.g. "years") or a :class:pint.Unit.
Validated against the shared registry on construction; an unrecognized string raises ValueError,
and a pint.Unit is stored as its canonical name.
QATask
dataclass
¶source
Bases: TargetTask
A question and its answer (the target).
sample_ids
class-attribute
instance-attribute
¶source
Ids of the samples this task targets, populated by add_task.
ReasoningTask
dataclass
¶source
Bases: TargetTask
A question answered by reasoning to a final answer. Often composed via from_tasks.
Unlike :class:QATask (single-label answer), a reasoning task carries the chain of thought in
rationale. The target is the evaluation answer; the rationale is the reasoning trace to
train / fine-tune on (None when the source has no stored rationale).
rationale
class-attribute
instance-attribute
¶source
rationale: str | None = None
The reasoning trace to train on, or None when the source stores none.
sample_ids
class-attribute
instance-attribute
¶source
Ids of the samples this task targets, populated by add_task.
StaticAnnotation
dataclass
¶source
Bases: Annotation
Sample-scoped, time-independent context. Carries a required value and no time fields.
description
class-attribute
instance-attribute
¶source
description: str | None = None
Optional human-readable description of the annotation.
unit
class-attribute
instance-attribute
¶source
unit: str | Unit | None = None
Optional physical unit of value — a unit string (e.g. "years") or a :class:pint.Unit.
Validated against the shared registry on construction; an unrecognized string raises ValueError,
and a pint.Unit is stored as its canonical name.
TargetTask
dataclass
¶source
Bases: Task
Base for tasks that carry a single supervised target.
Every task type except :class:ForecastingTask derives from this, so generic training code can read
task.target without knowing the concrete type (see
:meth:~timenet.dataset.TimeFDataset.to_features_and_targets). Not instantiated directly.
sample_ids
class-attribute
instance-attribute
¶source
Ids of the samples this task targets, populated by add_task.
Task
dataclass
¶source
Base for all tasks. Not instantiated directly; subclasses declare task_type and a payload.
TaskType ¶source
TimeSeriesSpec
dataclass
¶source
The contract for a measurement modality: type tag, name, and the units of its axes.
data_source
class-attribute
instance-attribute
¶source
data_source: DataSource | None = None
Origin that produced this modality, if known.
spec_type
instance-attribute
¶source
spec_type: str
Type tag identifying the modality; used to filter datasets by spec type.
unit_sampling_rate
instance-attribute
¶source
Unit of the sampling rate; must have frequency dimensionality.
Version
dataclass
¶source
A major.minor.patch semantic version with non-negative integer components.
Frozen and ordered, so versions compare with the usual precedence
(Version(1, 2, 0) > Version(1, 1, 9)).
minor
instance-attribute
¶source
minor: int
Minor version. Incremented on backwards-compatible additions.
patch
instance-attribute
¶source
patch: int
Patch version. Incremented on backwards-compatible fixes.
parse
classmethod
¶source
Parse a major.minor.patch string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The version string to parse. |
required |
Returns:
| Type | Description |
|---|---|
Version
|
The parsed :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
View ¶source
Bases: StrEnum
Identifies which slice of the source a :class:~timenet.dataset.Sample represents.
annotation_type_of ¶source
annotation_type_of(
annotation: Annotation,
) -> AnnotationType
Return the :class:AnnotationType shape of an annotation instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation
|
Annotation
|
The annotation to classify. |
required |
Returns:
| Type | Description |
|---|---|
AnnotationType
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
new_id ¶source
new_id() -> str
Return a new canonical UUIDv7 string, the default id for every TimeF entity.
Returns:
| Type | Description |
|---|---|
str
|
The canonical 36-character UUIDv7 string (time-ordered). |
uuid7 ¶source
uuid7() -> UUID
Return a UUIDv7 (RFC 9562 §5.7): 48-bit ms timestamp, then random bits.
Returns:
| Type | Description |
|---|---|
UUID
|
A version-7 :class: |
value_type_of ¶source
Return the manifest value_type tag for an annotation value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The annotation's value. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
One of |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |