From 070c04d2e036f4f0bebc277c64235e5c0593ab74 Mon Sep 17 00:00:00 2001 From: Xinyu Hu Date: Fri, 14 Jun 2024 15:35:35 -0400 Subject: [PATCH] Added "id" parameter for make_forecaseting_frame so that it will not have hard coded 'id' in the result --- tsfresh/utilities/dataframe_functions.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tsfresh/utilities/dataframe_functions.py b/tsfresh/utilities/dataframe_functions.py index ca6e128d..066310ed 100644 --- a/tsfresh/utilities/dataframe_functions.py +++ b/tsfresh/utilities/dataframe_functions.py @@ -579,7 +579,7 @@ def roll_time_series( return df_shift.sort_values(by=["id", column_sort or "sort"]) -def make_forecasting_frame(x, kind, max_timeshift, rolling_direction): +def make_forecasting_frame(x, id, kind, max_timeshift, rolling_direction): """ Takes a singular time series x and constructs a DataFrame df and target vector y that can be used for a time series forecasting task. @@ -597,6 +597,8 @@ def make_forecasting_frame(x, kind, max_timeshift, rolling_direction): :param x: the singular time series :type x: np.array or pd.Series + :param id: the id for the time series + :type id: str :param kind: the kind of the time series :type kind: str :param rolling_direction: The sign decides, if to roll backwards (if sign is positive) or forwards in "time" @@ -614,7 +616,7 @@ def make_forecasting_frame(x, kind, max_timeshift, rolling_direction): else: t = range(n) - df = pd.DataFrame({"id": ["id"] * n, "time": t, "value": x, "kind": kind}) + df = pd.DataFrame({"id": id, "time": t, "value": x, "kind": kind}) df_shift = roll_time_series( df, @@ -644,7 +646,7 @@ def mask_first(x): # make sure that the format is the same as the # df_shift index - y.index = map(lambda x: ("id", x), y.index) + y.index = map(lambda x: (id, x), y.index) return df_shift, y