{"record":{"id":"0cb2fcd9b7a09363","repo":"google-research/timesfm","slug":"train-dynamic-categorical-covariates-and-test-dyna","errorCode":null,"errorMessage":"train_dynamic_categorical_covariates and test_dynamic_categorical_covariates must be both present or both absent.","messagePattern":"train_dynamic_categorical_covariates and test_dynamic_categorical_covariates must be both present or both absent\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/timesfm/utils/xreg_lib.py","lineNumber":234,"sourceCode":"      and not self.test_dynamic_numerical_covariates\n    ) or (\n      not self.train_dynamic_numerical_covariates\n      and self.test_dynamic_numerical_covariates\n    ):\n      raise ValueError(\n        \"train_dynamic_numerical_covariates and\"\n        \" test_dynamic_numerical_covariates must be both present or both\"\n        \" absent.\"\n      )\n\n    if (\n      self.train_dynamic_categorical_covariates\n      and not self.test_dynamic_categorical_covariates\n    ) or (\n      not self.train_dynamic_categorical_covariates\n      and self.test_dynamic_categorical_covariates\n    ):\n      raise ValueError(\n        \"train_dynamic_categorical_covariates and\"\n        \" test_dynamic_categorical_covariates must be both present or both\"\n        \" absent.\"\n      )\n\n    # Check keys.\n    for dict_a, dict_b, dict_a_name, dict_b_name in (\n      (\n        self.train_dynamic_numerical_covariates,\n        self.test_dynamic_numerical_covariates,\n        \"train_dynamic_numerical_covariates\",\n        \"test_dynamic_numerical_covariates\",\n      ),\n      (\n        self.train_dynamic_categorical_covariates,\n        self.test_dynamic_categorical_covariates,\n        \"train_dynamic_categorical_covariates\",\n        \"test_dynamic_categorical_covariates\",","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/google-research/timesfm/blob/331c6d33cb1ac2611de3056d0ac7164aab6301eb/src/timesfm/utils/xreg_lib.py#L216-L252","documentation":"Identical symmetry check as error 35 but for dynamic categorical covariates: train_dynamic_categorical_covariates and test_dynamic_categorical_covariates must both be present or both absent, otherwise _assert_covariates raises this ValueError.","triggerScenarios":"Calling create_covariate_matrix (via forecast_with_covariates) with train_dynamic_categorical_covariates set and test_dynamic_categorical_covariates None, or the reverse.","commonSituations":"Adding categorical regressors (e.g. promotion flags) for training only; forgetting that future category values must also be supplied; partial refactoring of covariate code.","solutions":["Supply both train and test dynamic categorical covariate dicts with the same keys.","Pass None for both if categorical covariates are not used.","Fill test-side values with known future values (e.g. planned promotions, calendar categories)."],"exampleFix":"// before\nXregCovariates(train_dynamic_categorical_covariates={\"promo\": train_promo}, test_dynamic_categorical_covariates=None)\n// after\nXregCovariates(train_dynamic_categorical_covariates={\"promo\": train_promo}, test_dynamic_categorical_covariates={\"promo\": test_promo})","handlingStrategy":"validation","validationCode":"assert (train_cat is None) == (test_cat is None), \\\n    \"train and test dynamic categorical covariates must be both present or both absent\"","typeGuard":"def categoricals_symmetric(train_cat, test_cat) -> bool:\n    return (train_cat is None) == (test_cat is None)","tryCatchPattern":"try:\n    forecaster.forecast_with_covariates(...)\nexcept ValueError as e:\n    if \"dynamic_categorical_covariates must be both present\" in str(e):\n        test_cat = {k: planned_values[k] for k in train_cat}\n        forecaster.forecast_with_covariates(...)\n    else:\n        raise","preventionTips":["Define future categorical values (promos, holidays) up front alongside training ones","Never populate only the train dict","Centralize covariate construction so both sides are filled from the same source"],"tags":["python","covariates","valueerror","validation"],"backgroundTag":"covariate-mismatch","analyzedSha":"331c6d33cb1ac2611de3056d0ac7164aab6301eb","analyzedAt":"2026-08-29T01:04:23.138Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}