{"record":{"id":"d18f21ca9b71f8b7","repo":"google-research/timesfm","slug":"unsupported-array-shape-x-shape","errorCode":null,"errorMessage":"Unsupported array shape: {x.shape}","messagePattern":"Unsupported array shape: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/timesfm/utils/xreg_lib.py","lineNumber":57,"sourceCode":"\ndef _repeat(elements: Iterable[Any], counts: Iterable[int]) -> np.ndarray:\n  return np.array(\n    list(itertools.chain.from_iterable(map(itertools.repeat, elements, counts)))\n  )\n\n\ndef _to_padded_jax_array(x: np.ndarray) -> jax.Array:\n  if x.ndim == 1:\n    (i,) = x.shape\n    di = 2 ** math.ceil(math.log2(i)) - i\n    return jnp.pad(x, ((0, di),), mode=\"constant\", constant_values=0.0)\n  elif x.ndim == 2:\n    i, j = x.shape\n    di = 2 ** math.ceil(math.log2(i)) - i\n    dj = 2 ** math.ceil(math.log2(j)) - j\n    return jnp.pad(x, ((0, di), (0, dj)), mode=\"constant\", constant_values=0.0)\n  else:\n    raise ValueError(f\"Unsupported array shape: {x.shape}\")\n\n\n# Per time series normalization: forward.\ndef normalize(batch):\n  stats = [(np.mean(x), np.where((w := np.std(x)) > _TOL, w, 1.0)) for x in batch]\n  new_batch = [(x - stat[0]) / stat[1] for x, stat in zip(batch, stats)]\n  return new_batch, stats\n\n\n# Per time series normalization: inverse.\ndef renormalize(batch, stats):\n  return [x * stat[1] + stat[0] for x, stat in zip(batch, stats)]\n\n\nclass BatchedInContextXRegBase:\n  \"\"\"Helper class for in-context regression covariate formatting.\n\n  Attributes:","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/google-research/timesfm/blob/331c6d33cb1ac2611de3056d0ac7164aab6301eb/src/timesfm/utils/xreg_lib.py#L39-L75","documentation":"_to_padded_jax_array pads each covariate array to powers of two, but only handles 1-D and 2-D arrays. Passing an array with ndim >= 3 (or other unsupported shape) raises this ValueError.","triggerScenarios":"Calling xreg fit() (which calls _to_padded_jax_array) with dynamic numerical/categorical covariate arrays that have 3+ dimensions, e.g. shape (n_series, horizon, extra_dim) or mis-shaped lists converted to 3-D numpy arrays.","commonSituations":"Supplying covariates as nested lists with an unintended extra dimension (e.g. np.array of ragged/extra-nested lists), or passing multi-feature covariates where the API expects one array per series per covariate.","solutions":["Reshape the covariate array to 1-D or 2-D (per-series 1-D arrays of shape (horizon,) or 2-D (n, horizon)).","Check x.ndim/x.shape with numpy before passing; squeeze or drop the extra axis.","Split multi-feature covariates into separate named covariates in train_dynamic_numerical_covariates/test_dynamic_numerical_covariates."],"exampleFix":"// before\nnp.array(cov).shape  # (5, 10, 3)\n// after\nnp.array(cov).reshape(5, 30).shape  # or split into 3 named covariates of shape (5, 10)","handlingStrategy":"type-guard","validationCode":"import numpy as np\ncov = np.asarray(cov_array)\nif cov.ndim > 2:\n    raise ValueError(f\"Covariate array must be 1-D or 2-D, got shape {cov.shape}\")","typeGuard":"def is_padded_compatible(x) -> bool:\n    import numpy as np\n    a = np.asarray(x)\n    return a.ndim in (1, 2)","tryCatchPattern":"try:\n    covs.create_covariate_matrix()\nexcept ValueError as e:\n    if \"Unsupported array shape\" in str(e):\n        cov_array = np.asarray(cov_array).reshape(len(series), horizon)\n        covs.create_covariate_matrix()\n    else:\n        raise","preventionTips":["np.asarray + check .ndim before passing covariates","Avoid np.array on ragged nested lists (can produce object/3-D arrays)","Keep one covariate per named dict key rather than stacking features"],"tags":["python","numpy","valueerror","shape"],"backgroundTag":"array-shape-mismatch","analyzedSha":"331c6d33cb1ac2611de3056d0ac7164aab6301eb","analyzedAt":"2026-08-29T01:04:23.138Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}