Skip to content

Commit

Permalink
fix: static spec ignored outcome col name override
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff committed Dec 19, 2022
1 parent d07ff2b commit 5ec6892
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/timeseriesflattener/flattened_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ def _add_static_info(
else:
value_col_name = static_spec.input_col_name_override

if static_spec.feature_name is None:
if static_spec.output_col_name_override is not None:
output_col_name = static_spec.output_col_name_override
elif static_spec.feature_name is None:
output_col_name = f"{static_spec.prefix}_{value_col_name}"
elif static_spec.feature_name:
output_col_name = f"{static_spec.prefix}_{static_spec.feature_name}"
Expand Down Expand Up @@ -891,8 +893,8 @@ def compute(self):
log.warning("No unprocessed specs, skipping")
return

self._process_temporal_specs()
self._process_static_specs()
self._process_temporal_specs()

def get_df(self) -> DataFrame:
"""Get the flattened dataframe. Computes if any unprocessed specs are present.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_add_multiple_static_predictors():
2,2021-12-31 00:00:01, 1
"""

expected_df_str = """entity_id,timestamp,outc_value_within_2_days_max_fallback_0_dichotomous,pred_age_in_years,pred_male
expected_df_str = """entity_id,timestamp,outc_value_within_2_days_max_fallback_0_dichotomous,pred_age_in_years,pred_male_overridden
1,2021-12-31 00:00:00, 1.0,22.00,1
2,2021-12-31 00:00:00, 1.0,22.00,0
3,2023-12-31 00:00:00, 0.0,23.99,1
Expand Down Expand Up @@ -412,6 +412,7 @@ def test_add_multiple_static_predictors():
feature_name="male",
prefix="pred",
input_col_name_override="male",
output_col_name_override="pred_male_overridden",
),
],
)
Expand All @@ -428,11 +429,11 @@ def test_add_multiple_static_predictors():
"timestamp",
"outc_value_within_2_days_max_fallback_0_dichotomous",
"pred_age_in_years",
"pred_male",
"pred_male_overridden",
):
pd.testing.assert_series_equal(
outcome_df[col],
expected_df[col],
outcome_df[col].reset_index(drop=True),
expected_df[col].reset_index(drop=True),
check_dtype=False,
)

Expand Down

0 comments on commit 5ec6892

Please sign in to comment.