Skip to content

Commit

Permalink
fix: use Union in pydantic basemodels
Browse files Browse the repository at this point in the history
  • Loading branch information
HLasse committed May 17, 2024
1 parent fc46ef3 commit a80a9c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/timeseriesflattener/v1/feature_specs/group_specs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
import itertools
from dataclasses import dataclass
from typing import Dict, List, Sequence, Tuple
from typing import Dict, List, Sequence, Tuple, Union

import pandas as pd
from timeseriesflattener.v1.aggregation_fns import AggregationFunType
Expand Down Expand Up @@ -40,10 +40,10 @@ class PredictorGroupSpec(BaseModel):
"""

# Shared attributes from GroupSpec
lookbehind_days: Sequence[float | Tuple[float, float]]
lookbehind_days: Sequence[Union[float, Tuple[float, float]]]
named_dataframes: Sequence[NamedDataframe]
aggregation_fns: Sequence[AggregationFunType]
fallback: Sequence[int | float | str]
fallback: Sequence[Union[int, float, str]]
prefix: str = "pred"

def create_combinations(self) -> List[PredictorSpec]:
Expand Down Expand Up @@ -82,10 +82,10 @@ class OutcomeGroupSpec(BaseModel):
prefix: str = "outc"
named_dataframes: Sequence[NamedDataframe]
aggregation_fns: Sequence[AggregationFunType]
fallback: Sequence[int | float | str]
fallback: Sequence[Union[int, float, str]]

# Individual attributes
lookahead_days: Sequence[float | Tuple[float, float]]
lookahead_days: Sequence[Union[float, Tuple[float, float]]]
incident: Sequence[bool]

def create_combinations(self) -> List[OutcomeSpec]:
Expand Down
10 changes: 5 additions & 5 deletions src/timeseriesflattener/v1/feature_specs/single_specs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import Tuple
from typing import Tuple, Union

import pandas as pd
from timeseriesflattener.v1.aggregation_fns import AggregationFunType
Expand Down Expand Up @@ -117,9 +117,9 @@ class OutcomeSpec(BaseModel):

timeseries_df: pd.DataFrame
feature_base_name: str
lookahead_days: float | Tuple[float, float]
lookahead_days: Union[float, Tuple[float, float]]
aggregation_fn: AggregationFunType
fallback: float | int
fallback: Union[float, int]
incident: bool
prefix: str = "outc"

Expand Down Expand Up @@ -171,8 +171,8 @@ class PredictorSpec(BaseModel):
timeseries_df: pd.DataFrame
feature_base_name: str
aggregation_fn: AggregationFunType
fallback: float | int
lookbehind_days: float | Tuple[float, float]
fallback: Union[float, int]
lookbehind_days: Union[float, Tuple[float, float]]
prefix: str = "pred"

@property
Expand Down

0 comments on commit a80a9c2

Please sign in to comment.