Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docstring to flattener #568

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/timeseriesflattener/flattener.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,25 @@ class Flattener:
predictiontime_frame: PredictionTimeFrame
compute_lazily: bool = False
n_workers: int | None = None
"""Flatten multiple irregular time series to a static feature set.
Args:
predictiontime_frame: A frame that contains the prediction times.
compute_lazily: If True, the computation will be done lazily.
n_workers: The number of workers to use for multiprocessing.
If None, multiprocessing will be handled entirely by polars, otherwise,
specify the number of workers to use with joblib. """

def aggregate_timeseries(
self, specs: Sequence[ValueSpecification], step_size: dt.timedelta | None = None
) -> AggregatedFrame:
"""Perform the aggregation/flattening.
Args:
specs: The specifications for the features to be created.
step_size: The step size for the aggregation.
If not None, will aggregate prediction times in chunks of step_size.
Reduce if you encounter memory issues."""
if self.compute_lazily:
print(
"We have encountered performance issues on Windows when using lazy evaluation. If you encounter performance issues, try setting lazy=False."
Expand Down
8 changes: 5 additions & 3 deletions src/timeseriesflattener/test_aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SingleVarAggregatorExample:
aggregator: Aggregator
input_values: Sequence[float | None]
expected_output_values: Sequence[float]
fallback_str: str = "nan"

@property
def input_frame(self) -> pl.LazyFrame:
Expand All @@ -58,7 +59,7 @@ def expected_output(self) -> pl.DataFrame:
return pl.DataFrame(
{
"prediction_time_uuid": [1],
f"value_{self.aggregator.name}_fallback_nan": self.expected_output_values,
f"value_{self.aggregator.name}_fallback_{self.fallback_str}": self.expected_output_values,
}
)

Expand Down Expand Up @@ -90,12 +91,13 @@ def expected_output(self) -> pl.DataFrame:
aggregator=VarianceAggregator(), input_values=[1, 2], expected_output_values=[0.5]
),
SingleVarAggregatorExample(
aggregator=HasValuesAggregator(), input_values=[1, 2], expected_output_values=[1]
aggregator=HasValuesAggregator(), input_values=[1, 2], expected_output_values=[1], fallback_str="False"
),
SingleVarAggregatorExample(
aggregator=HasValuesAggregator(),
input_values=[None], # type: ignore
expected_output_values=[0],
fallback_str="False",
),
ComplexAggregatorExample(
aggregator=SlopeAggregator(timestamp_col_name="timestamp"),
Expand Down Expand Up @@ -153,7 +155,7 @@ def test_aggregator(example: AggregatorExampleType):
timestamp_col_name="timestamp",
),
aggregators=[example.aggregator],
fallback=np.nan,
fallback=np.nan if example.aggregator.name != "bool" else False,
)

assert_frame_equal(result.collect(), example.expected_output)
Loading