{"record":{"id":"9c2b6d3725f0d823","repo":"commaai/openpilot","slug":"time-value-arrays-must-have-the-same-shape-got-r","errorCode":null,"errorMessage":"Time/value arrays must have the same shape, got {result_t.shape} and {result_v.shape}","messagePattern":"Time/value arrays must have the same shape, got (.+?) and (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openpilot/tools/jotpluggler/math_eval.py","lineNumber":133,"sourceCode":"\n  with open(code_path, encoding=\"utf-8\") as f:\n    user_code = f.read()\n  result = _evaluate_user_code(user_code, env)\n\n  if isinstance(result, tuple) and len(result) == 2:\n    result_t, result_v = result\n  else:\n    if first_path is None:\n      raise ValueError(\"No reference series found. Set an input timeseries or return (times, values).\")\n    result_t = series_t[first_path]\n    result_v = result\n\n  result_t = np.asarray(result_t, dtype=np.float64).reshape(-1)\n  result_v = np.asarray(result_v, dtype=np.float64).reshape(-1)\n  if result_t.size == 0 or result_v.size == 0:\n    raise ValueError(\"Custom series returned an empty result\")\n  if result_t.shape != result_v.shape:\n    raise ValueError(f\"Time/value arrays must have the same shape, got {result_t.shape} and {result_v.shape}\")\n\n  _write_vector(out_t_path, result_t)\n  _write_vector(out_v_path, result_v)\n  return 0\n\n\nif __name__ == \"__main__\":\n  try:\n    raise SystemExit(main())\n  except Exception as err:\n    traceback.print_exc()\n    raise SystemExit(1) from err\n","sourceCodeStart":115,"sourceCodeEnd":146,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/tools/jotpluggler/math_eval.py#L115-L146","documentation":"The evaluated result's time array and value array must have identical 1-D shapes after np.asarray(...).reshape(-1). Mismatched lengths mean the values cannot be aligned to timestamps, so writing the output vector pair would corrupt the timeseries. The message includes both shapes to make the mismatch obvious.","triggerScenarios":"Returning (times, values) where values was computed from a differently-sized array (e.g. times from series A, values from a resampled/filtered series B); returning a tuple whose elements come from different inputs; off-by-one from slicing one array but not the other.","commonSituations":"Mixing two input series of different lengths in one expression; computing values on a masked array but keeping unmasked times; interpolation changing length of only one array.","solutions":["Make both arrays derive from the same source: slice/mask times and values with the identical mask","If lengths differ by design, resample one to the other (np.interp) before returning","Print both shapes in the code file to spot the divergence point"],"exampleFix":"# before\nreturn (series_t['a'], series_v['b'])  # different lengths\n\n# after\nmask = series_t['a'] >= 0\nreturn (series_t['a'][mask], np.interp(series_t['a'][mask], series_t['b'], series_v['b']))","handlingStrategy":"validation","validationCode":"t = np.asarray(result_t, dtype=np.float64).reshape(-1)\nv = np.asarray(result_v, dtype=np.float64).reshape(-1)\nassert t.shape == v.shape, f\"times {t.shape} vs values {v.shape} - align arrays before writing\"","typeGuard":"def aligned_timeseries(t, v) -> bool:\n    \"\"\"True when time and value arrays are same-length 1-D float arrays.\"\"\"\n    t, v = np.asarray(t), np.asarray(v)\n    return t.ndim == 1 and v.ndim == 1 and t.shape == v.shape","tryCatchPattern":"try:\n    _write_vector(out_t_path, result_t)\n    _write_vector(out_v_path, result_v)\nexcept ValueError as e:\n    if 'same shape' in str(e):\n        raise SystemExit('time/value length mismatch - apply the same mask to both arrays')\n    raise","preventionTips":["Apply identical masks/slices to times and values in metric code; never slice only one","When combining series, np.interp values onto the chosen timebase before returning"],"tags":["jotpluggler","math-eval","shape-mismatch","numpy","openpilot"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}