Skip to content

fix: raise clear error when id_col is not found in dataframe#754

Open
W057 wants to merge 3 commits intoNixtla:mainfrom
W057:fix/issue-565-id-col-validation
Open

fix: raise clear error when id_col is not found in dataframe#754
W057 wants to merge 3 commits intoNixtla:mainfrom
W057:fix/issue-565-id-col-validation

Conversation

@W057
Copy link
Copy Markdown

@W057 W057 commented Feb 15, 2026

Summary

  • Raises ValueError with a clear message when id_col is not found in the dataframe columns, instead of silently creating a dummy ID that causes confusing downstream errors about timestamps
  • Accepts id_col=None for single-series DataFrames without an ID column, as discussed in [bug] error message is not correct #565

Changes

nixtla/nixtla_client.py

  • Updated _run_validations() to check if id_col exists in columns and raise ValueError if not
  • When id_col=None, creates a dummy unique_id column (explicit single-series mode)
  • Updated type hints from str to Optional[str] in finetune, forecast, detect_anomalies, detect_anomalies_online, cross_validation

Breaking change

DataFrames without a unique_id column that relied on the implicit dummy ID behavior will now get a clear error message guiding them to use id_col=None. This was discussed and agreed upon in #565 by @jmoralez and @ngupta23.

Test plan

  • Wrong id_col (e.g. id_col="Sth") raises ValueError with column name and suggestion
  • id_col=None creates dummy ID for single series
  • Default id_col="unique_id" with column present works normally
  • Default id_col="unique_id" without column raises clear error
  • Custom id_col that exists in columns works normally
  • id_col=None with X_df also adds dummy ID to X_df

Closes #565

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bacb817d69

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread nixtla/nixtla_client.py
Comment on lines +1112 to +1114
if id_col is None:
id_col = "unique_id"
drop_id = True
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return normalized id_col from validations

When id_col=None, this function rewrites id_col to 'unique_id', but the updated value is not returned to callers; downstream methods still use the original None when calling _preprocess/_validate_exog (for example in forecast and cross_validation). In that path, _run_validations creates a 'unique_id' column while later code looks for column None, which causes failures before the API call and breaks the new single-series id_col=None behavior introduced by this commit.

Useful? React with 👍 / 👎.

W057 added 2 commits February 19, 2026 16:21
Previously, passing a wrong id_col (e.g. id_col="Sth") would silently
create a dummy ID column, leading to confusing downstream errors about
timestamps. Now raises ValueError with the column name and available
columns.

Also accepts id_col=None for single-series DataFrames without an
ID column, as discussed with @jmoralez and @ngupta23.

Closes Nixtla#565
When id_col=None is passed, _run_validations rewrites it to
"unique_id" internally but previously did not return the updated
value. This caused downstream functions (_preprocess, _validate_exog,
_maybe_drop_id) to receive None instead of "unique_id", breaking
the id_col=None single-series flow.

Now _run_validations returns id_col as part of its tuple, and all 5
callers (finetune, forecast, detect_anomalies, detect_anomalies_online,
cross_validation) capture and use the normalized value.
@W057 W057 force-pushed the fix/issue-565-id-col-validation branch from d3b4d1f to abf270e Compare February 19, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] error message is not correct

2 participants