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

fix: wide dataframe #64

Merged
merged 3 commits into from
Aug 7, 2023
Merged
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
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -13,3 +13,4 @@ dependencies:
- python-dotenv
- statsforecast
- requests
- openbb
757 changes: 752 additions & 5 deletions nbs/timegpt.ipynb

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion nixtlats/timegpt.py
Original file line number Diff line number Diff line change
@@ -67,6 +67,8 @@ def _validate_inputs(
):
renamer = {id_col: "unique_id", time_col: "ds", target_col: "y"}
df = df.rename(columns=renamer)
if df.dtypes.ds != "object":
df["ds"] = df["ds"].astype(str)
drop_uid = False
if "unique_id" not in df.columns:
# Insert unique_id column
@@ -76,6 +78,8 @@ def _validate_inputs(
X_df = X_df.rename(columns=renamer)
if "unique_id" not in df.columns:
X_df = X_df.assign(unique_id="ts_0")
if X_df.dtypes.ds != "object":
X_df["ds"] = X_df["ds"].astype(str)
return df, X_df, drop_uid

def _validate_outputs(
@@ -122,9 +126,14 @@ def _preprocess_inputs(
to_dict_args["index"] = False
y = y.to_dict(**to_dict_args)
x_cols = df.drop(columns=y_cols).columns.to_list()
if len(x_cols) == 0:
if len(x_cols) == 0 or X_df is None:
x = None
else:
if not all(col in X_df.columns for col in x_cols):
raise Exception(
"You must pass the future values of these "
f'exogenous variables {",".join(x_cols)}'
)
x = pd.concat(
[
df[["unique_id", "ds"] + x_cols]