{"record":{"id":"924fbdf9b1e37d61","repo":"google-research/timesfm","slug":"dict-a-name-has-keys-not-present-in-dict-b-name","errorCode":null,"errorMessage":"{dict_a_name} has keys not present in {dict_b_name}: {w}","messagePattern":"(.+?) has keys not present in (.+?): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/timesfm/utils/xreg_lib.py","lineNumber":256,"sourceCode":"      )\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\",\n      ),\n    ):\n      if w := set(dict_a.keys()) - set(dict_b.keys()):\n        raise ValueError(f\"{dict_a_name} has keys not present in {dict_b_name}: {w}\")\n      if w := set(dict_b.keys()) - set(dict_a.keys()):\n        raise ValueError(f\"{dict_b_name} has keys not present in {dict_a_name}: {w}\")\n\n    # Check shapes.\n    if assert_covariate_shapes:\n      if len(self.targets) != len(self.train_lens):\n        raise ValueError(\n          \"targets and train_lens must have the same number of elements.\"\n        )\n\n      if len(self.train_lens) != len(self.test_lens):\n        raise ValueError(\n          \"train_lens and test_lens must have the same number of elements.\"\n        )\n\n      for i, (target, train_len) in enumerate(zip(self.targets, self.train_lens)):\n        if len(target) != train_len:\n          raise ValueError(","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/google-research/timesfm/blob/331c6d33cb1ac2611de3056d0ac7164aab6301eb/src/timesfm/utils/xreg_lib.py#L238-L274","documentation":"During covariate validation, each train/test dict pair is compared by key set. If the train-side dict contains keys missing from the test-side dict, this ValueError lists those extra keys (format: \"{dict_a_name} has keys not present in {dict_b_name}: {...}\").","triggerScenarios":"create_covariate_matrix → _assert_covariates with dicts whose key sets differ, e.g. train dict has covariate \"holiday\" but the test dict does not.","commonSituations":"Adding a new covariate to training data but forgetting to add it to test data; typos in dict keys; serializing covariates from different data sources with inconsistent naming.","solutions":["Add the missing key(s) to the test-side dict with arrays of length equal to the forecast horizon.","Remove the extra key(s) from the train-side dict if the covariate is not needed.","Assert set(train.keys()) == set(test.keys()) in your own code before calling the forecaster."],"exampleFix":"// before\ntrain = {\"promo\": a, \"holiday\": b}; test = {\"promo\": c}\n// after\ntrain = {\"promo\": a, \"holiday\": b}; test = {\"promo\": c, \"holiday\": d}","handlingStrategy":"validation","validationCode":"extra = set(train_cat.keys()) - set(test_cat.keys())\nif extra:\n    raise ValueError(f\"Missing test-side covariate keys: {extra}\")","typeGuard":"def keys_match(train_dict, test_dict) -> bool:\n    return set(train_dict.keys()) == set(test_dict.keys())","tryCatchPattern":"try:\n    covs.create_covariate_matrix()\nexcept ValueError as e:\n    if \"has keys not present in\" in str(e):\n        print(\"Align train/test covariate keys, then retry:\", e)\n        raise","preventionTips":["Keep covariate names in a shared constant list used to build both dicts","Check key-set equality before calling the forecaster","Watch for typos causing duplicate 'different' keys"],"tags":["python","covariates","valueerror","validation"],"backgroundTag":"covariate-key-mismatch","analyzedSha":"331c6d33cb1ac2611de3056d0ac7164aab6301eb","analyzedAt":"2026-08-29T01:04:23.138Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}