Skip to content

Commit

Permalink
Merge pull request #86 from FastTrackiverse/67-candidatetracks-should…
Browse files Browse the repository at this point in the history
…-be-indexable-iterable

candidate tracks now indexable
  • Loading branch information
JoFrhwld authored Jun 26, 2024
2 parents 476ea73 + afa2660 commit 6248fe9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/fasttrackpy/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from aligned_textgrid.sequences.tiers import TierGroup

import polars as pl
from collections.abc import Sequence

from typing import Union, Literal
import warnings
Expand Down Expand Up @@ -381,7 +382,7 @@ def spectrogram(self, **kwargs):



class CandidateTracks(Track):
class CandidateTracks(Track, Sequence):
"""A class for candidate tracks for a single formant
You can provide *either*
Expand Down Expand Up @@ -510,6 +511,12 @@ def __init__(

self.winner_idx = np.argmin(self.smooth_errors)
self.winner = self.candidates[self.winner_idx]

def __getitem__(self, idx:int) -> OneTrack:
return self.candidates[idx]

def __len__(self) -> int:
return len(self.candidates)

@property
def file_name(self):
Expand Down
12 changes: 11 additions & 1 deletion tests/test_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ def test_candidate_tracks_default(self):
big_df4 = candidates.to_df(which = "all", output="param")

assert isinstance(big_df3, pl.DataFrame)
assert isinstance(big_df4, pl.DataFrame)
assert isinstance(big_df4, pl.DataFrame)

def test_candidate_sequence(self):
candidates = CandidateTracks(
sound = SOUND
)

assert len(candidates) == 20

one_cand = candidates[0]
assert isinstance(one_cand, OneTrack)

0 comments on commit 6248fe9

Please sign in to comment.