From b6b0c653f5bb9d99981d54c3f83c3edc259c3417 Mon Sep 17 00:00:00 2001 From: Gregor Lenz Date: Fri, 30 Dec 2022 14:57:54 +0100 Subject: [PATCH] add runtime_checkable to Slicer class to allow type checking slicers --- tonic/slicers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tonic/slicers.py b/tonic/slicers.py index 7905725f..743c556d 100644 --- a/tonic/slicers.py +++ b/tonic/slicers.py @@ -1,10 +1,11 @@ from dataclasses import dataclass -from typing import Any, List, Tuple +from typing import Any, List, Tuple, runtime_checkable import numpy as np from typing_extensions import Protocol +@runtime_checkable class Slicer(Protocol): """Base protocol class for slicers in Tonic. @@ -101,7 +102,7 @@ def slice_with_metadata( return [data[start:end] for start, end in metadata], targets -@dataclass +@dataclass(frozen=True) class SliceByTimeBins: """ Slices data and targets along fixed number of bins of time length time_duration / bin_count * (1 + overlap).