{"record":{"id":"2cef47b2b607590f","repo":"google-research/timesfm","slug":"train-dynamic-numerical-covariates-and-test-dynami","errorCode":null,"errorMessage":"train_dynamic_numerical_covariates and test_dynamic_numerical_covariates must be both present or both absent.","messagePattern":"train_dynamic_numerical_covariates and test_dynamic_numerical_covariates must be both present or both absent\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/timesfm/utils/xreg_lib.py","lineNumber":221,"sourceCode":"      train_dynamic_categorical_covariates or {}\n    )\n    self.test_dynamic_numerical_covariates = test_dynamic_numerical_covariates or {}\n    self.test_dynamic_categorical_covariates = test_dynamic_categorical_covariates or {}\n    self.static_numerical_covariates = static_numerical_covariates or {}\n    self.static_categorical_covariates = static_categorical_covariates or {}\n\n  def _assert_covariates(self, assert_covariate_shapes: bool = False) -> None:\n    \"\"\"Verifies the validity of the covariate inputs.\"\"\"\n\n    # Check presence.\n    if (\n      self.train_dynamic_numerical_covariates\n      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","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/google-research/timesfm/blob/331c6d33cb1ac2611de3056d0ac7164aab6301eb/src/timesfm/utils/xreg_lib.py#L203-L239","documentation":"_assert_covariates enforces that dynamic numerical covariates are provided symmetrically: train_dynamic_numerical_covariates and test_dynamic_numerical_covariates must both be set or both be None. Supplying only one side raises this ValueError in create_covariate_matrix.","triggerScenarios":"Calling forecast_with_covariates / create_covariate_matrix passing train_dynamic_numerical_covariates without test_dynamic_numerical_covariates (or vice versa).","commonSituations":"Forecasting future points where users assume test covariates can be omitted; providing historical-only covariates for model fitting; copying examples that only show one dict.","solutions":["Provide both train_dynamic_numerical_covariates and test_dynamic_numerical_covariates with matching keys.","If no dynamic numerical covariates are intended, pass None (or omit) for both sides.","For future unknown values, supply placeholder/forecasted covariate values in the test dict."],"exampleFix":"// before\nforecast_with_covariates(inputs, dynamic_numerical_covariates=train_num, dynamic_categorical_covariates=None)\n// after\nforecast_with_covariates(inputs, dynamic_numerical_covariates=train_num, dynamic_categorical_covariates=None)  # ensure the API receives BOTH train_num and test_num dicts","handlingStrategy":"validation","validationCode":"assert (train_num is None) == (test_num is None), \\\n    \"train and test dynamic numerical covariates must be both present or both absent\"","typeGuard":"def numerics_symmetric(train_num, test_num) -> bool:\n    return (train_num is None) == (test_num is None)","tryCatchPattern":"try:\n    forecaster.forecast_with_covariates(...)\nexcept ValueError as e:\n    if \"dynamic_numerical_covariates must be both present\" in str(e):\n        test_num = {k: forecast_values for k in train_num}\n        forecaster.forecast_with_covariates(...)\n    else:\n        raise","preventionTips":["Build train/test covariate dicts together in one helper function","Pass None for BOTH sides when a covariate type is unused","Remember future covariates must be supplied even if values are forecasts/placeholders"],"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"}