{"record":{"id":"5a0e20fec6309a4b","repo":"jax-ml/jax","slug":"period-must-be-a-scalar-got-period","errorCode":null,"errorMessage":"period must be a scalar; got {period}","messagePattern":"period must be a scalar; got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":2626,"sourceCode":"      raise ValueError(\"the only valid string value of `left` is \"\n                       f\"'extrapolate', but got: {left!r}\")\n    extrapolate_left = True\n  else:\n    extrapolate_left = False\n  if isinstance(right, str):\n    if right != 'extrapolate':\n      raise ValueError(\"the only valid string value of `right` is \"\n                       f\"'extrapolate', but got: {right!r}\")\n    extrapolate_right = True\n  else:\n    extrapolate_right = False\n\n  if dtypes.issubdtype(x_arr.dtype, np.complexfloating):\n    raise ValueError(\"jnp.interp: complex x values not supported.\")\n\n  if period is not None:\n    if np.ndim(period) != 0:\n      raise ValueError(f\"period must be a scalar; got {period}\")\n    period = ufuncs.abs(period)\n    x_arr = x_arr % period\n    xp_arr = xp_arr % period\n    xp_arr, fp_arr = lax.sort_key_val(xp_arr, fp_arr)\n    xp_arr = concatenate([xp_arr[-1:] - period, xp_arr, xp_arr[:1] + period])\n    fp_arr = concatenate([fp_arr[-1:], fp_arr, fp_arr[:1]])\n\n  i = clip(searchsorted(xp_arr, x_arr, side='right'), 1, len(xp_arr) - 1)\n  df = fp_arr[i] - fp_arr[i - 1]\n  dx = xp_arr[i] - xp_arr[i - 1]\n  delta = x_arr - xp_arr[i - 1]\n\n  epsilon = np.spacing(np.finfo(xp_arr.dtype).eps)\n  dx0 = lax.abs(dx) <= epsilon  # Prevent NaN gradients when `dx` is small.\n  f = where(dx0, fp_arr[i - 1], fp_arr[i - 1] + (delta / where(dx0, 1, dx)) * df)\n\n  if not extrapolate_left:\n    assert not isinstance(left, str)","sourceCodeStart":2608,"sourceCodeEnd":2644,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L2608-L2644","documentation":"jnp.interp's period argument (for periodic interpolation) must be a scalar (0-dimensional). Passing an array or any non-scalar with ndim != 0 is rejected because periodic wrapping requires a single period value.","triggerScenarios":"Calling jnp.interp(x, xp, fp, period=jnp.array([2*np.pi])) or period=np.pi*np.ones(3); a 1-element list also triggers it.","commonSituations":"Wrapping a period in brackets accidentally, reusing a per-point periods array from custom interpolation code, or loading a period from config as a 1-element array.","solutions":["Pass a Python float or 0-d value: period=2*np.pi","If period comes from an array, index it: period=float(period[0]) or use period.item()","Verify np.ndim(period) == 0 before the call"],"exampleFix":"// before\njnp.interp(x, xp, fp, period=np.array([6.283185]))\n// after\njnp.interp(x, xp, fp, period=float(np.array([6.283185]).item()))","handlingStrategy":"validation","validationCode":"import numpy as np\nif np.ndim(period) != 0:\n    period = float(np.asarray(period).reshape(-1)[0])","typeGuard":"def is_scalar_period(p) -> bool:\n    return p is None or np.ndim(p) == 0","tryCatchPattern":null,"preventionTips":["Always pass period as a Python float","Assert np.ndim(period) == 0 in tests"],"tags":["jax","interp","period","shape-validation"],"backgroundTag":"argument-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}