• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rafaelpadilla / 3W / 24912462866

24 Apr 2026 09:21PM UTC coverage: 76.362% (-3.1%) from 79.464%
24912462866

push

github

web-flow
Merge pull request #73 from rafaelpadilla/eduardo/refactor_data_operations

Refactor of data operations, trainers and models.

244 of 339 branches covered (71.98%)

Branch coverage included in aggregate %.

1317 of 1706 new or added lines in 50 files covered. (77.2%)

28 existing lines in 5 files now uncovered.

2124 of 2762 relevant lines covered (76.9%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/toolkit/ThreeWToolkit/preprocessing/fill_labels.py
1
from typing import Literal
1✔
2
from pydantic import Field, field_validator, PrivateAttr, ValidationInfo
1✔
3

4
from ..core.base_dataset import BaseDataset
1✔
5
from ..core.base_preprocessing import BasePreprocessing, BasePreprocessingConfig
1✔
6
from ..core.dataset_outputs import DatasetOutputs
1✔
7

8

9
class FillLabelsConfig(BasePreprocessingConfig):
1✔
10
    """Configuration for FillLabels preprocessing step."""
11

12
    fill_method: Literal["nearest", "ffill", "bfill", "constant"] = Field(
1✔
13
        default="nearest", description="Method to fill missing values in labels."
14
    )
15
    fill_value: int | None = Field(
1✔
16
        default=None, description="Value to use when fill_method is 'constant'."
17
    )
18
    _target: type = PrivateAttr(default_factory=lambda: FillLabels)
1✔
19

20
    @field_validator("fill_value")
1✔
21
    @classmethod
1✔
22
    def validate_fill_value(cls, value: int | None, info: ValidationInfo) -> int | None:
1✔
23
        if info.data.get("fill_method") == "constant" and value is None:
1✔
NEW
24
            raise ValueError(
×
25
                "fill_value must be provided when fill_method is 'constant'."
26
            )
27
        return value
1✔
28

29

30
class FillLabels(BasePreprocessing):
1✔
31
    """
32
    Preprocessing step to fill missing values in label Series using bfill then ffill.
33
    Applies to each event's label data.
34
    """
35

36
    def __init__(self, config: FillLabelsConfig):
1✔
37
        """Initialize FillLabels preprocessing step with the given configuration.
38
        Args:
39
            config: Configuration for FillLabels preprocessing step.
40
        """
41
        self.config: FillLabelsConfig = config
1✔
42

43
    def fit(self, data: BaseDataset) -> None:
1✔
44
        """No fitting needed for this preprocessing step.
45

46
        Args:
47
            data: Dataset (not used).
48
        """
49
        pass
1✔
50

51
    def transform(self, data: DatasetOutputs) -> DatasetOutputs:
1✔
52
        """Fill missing label values using the configured strategy.
53

54
        Args:
55
            data: Dataset outputs with labels to fill.
56

57
        Returns:
58
            Dataset outputs with filled labels.
59
        """
60

61
        if data.label is None:  # Noop if there are no labels to fill
1✔
NEW
62
            return data
×
63

64
        if self.config.fill_method == "constant":
1✔
65
            label = data.label.fillna(self.config.fill_value)
1✔
66
        elif self.config.fill_method == "ffill":
1✔
67
            label = (
1✔
68
                data.label.ffill().bfill()
69
            )  # Fill missing values using forward fill then backward fill
70
        elif self.config.fill_method == "bfill":
1✔
71
            label = (
1✔
72
                data.label.bfill().ffill()
73
            )  # Fill missing values using backward fill then forward fill
74
        elif self.config.fill_method == "nearest":
1✔
75
            # Fill missing values using nearest interpolation then bfill and ffill to handle any remaining NaNs
76
            label = data.label.interpolate(method="nearest").bfill().ffill()
1✔
77
        else:
NEW
78
            raise ValueError(f"Unsupported fill method: {self.config.fill_method}")
×
79

80
        return DatasetOutputs(signal=data.signal, label=label, metadata=data.metadata)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc