google-research/timesfm · error · ValueError
Unsupported array shape: {x.shape}
Error message
Unsupported array shape: {x.shape} What it means
_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.
Source
Thrown at src/timesfm/utils/xreg_lib.py:57
def _repeat(elements: Iterable[Any], counts: Iterable[int]) -> np.ndarray:
return np.array(
list(itertools.chain.from_iterable(map(itertools.repeat, elements, counts)))
)
def _to_padded_jax_array(x: np.ndarray) -> jax.Array:
if x.ndim == 1:
(i,) = x.shape
di = 2 ** math.ceil(math.log2(i)) - i
return jnp.pad(x, ((0, di),), mode="constant", constant_values=0.0)
elif x.ndim == 2:
i, j = x.shape
di = 2 ** math.ceil(math.log2(i)) - i
dj = 2 ** math.ceil(math.log2(j)) - j
return jnp.pad(x, ((0, di), (0, dj)), mode="constant", constant_values=0.0)
else:
raise ValueError(f"Unsupported array shape: {x.shape}")
# Per time series normalization: forward.
def normalize(batch):
stats = [(np.mean(x), np.where((w := np.std(x)) > _TOL, w, 1.0)) for x in batch]
new_batch = [(x - stat[0]) / stat[1] for x, stat in zip(batch, stats)]
return new_batch, stats
# Per time series normalization: inverse.
def renormalize(batch, stats):
return [x * stat[1] + stat[0] for x, stat in zip(batch, stats)]
class BatchedInContextXRegBase:
"""Helper class for in-context regression covariate formatting.
Attributes:View on GitHub (pinned to 331c6d33cb)
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.
Example fix
// before np.array(cov).shape # (5, 10, 3) // after np.array(cov).reshape(5, 30).shape # or split into 3 named covariates of shape (5, 10)
Defensive patterns
Strategy: type-guard
Validate before calling
import numpy as np
cov = np.asarray(cov_array)
if cov.ndim > 2:
raise ValueError(f"Covariate array must be 1-D or 2-D, got shape {cov.shape}") Type guard
def is_padded_compatible(x) -> bool:
import numpy as np
a = np.asarray(x)
return a.ndim in (1, 2) Try / catch
try:
covs.create_covariate_matrix()
except ValueError as e:
if "Unsupported array shape" in str(e):
cov_array = np.asarray(cov_array).reshape(len(series), horizon)
covs.create_covariate_matrix()
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Output dims must be a multiple of 4: {config.output_dims} %
- Memory dimension ({self.qkv_features}) must be divisible by
- Layer norm: {config.attention_norm} not supported.
- Layer norm: {config.feedforward_norm} not supported.
- Activation: {config.ff_activation} not supported.
AI-assisted analysis of google-research/timesfm@331c6d33cb (2026-08-29).
Data as JSON: /api/errors/d18f21ca9b71f8b7.
Report an issue: GitHub.