jax-ml/jax · error · ValueError

the only valid string value of `left` is 'extrapolate', but

Error message

the only valid string value of `left` is 'extrapolate', but got: {left!r}

What it means

jnp.interp accepts the special string 'extrapolate' for the left argument (to extrapolate below the first xp point). Any other string value is rejected because the API only defines one valid string sentinel; numeric/scalar bounds are fine, strings other than 'extrapolate' are not.

Source

Thrown at jax/_src/numpy/lax_numpy.py:2608

    lax.add(atol, lax.mul(rtol, lax.abs(b))))
  out = ufuncs.logical_or(lax.eq(a, b), ufuncs.logical_and(check_fin, in_range))
  return ufuncs.logical_or(out, both_nan) if equal_nan else out


def _interp(x: ArrayLike, xp: ArrayLike, fp: ArrayLike,
           left: ArrayLike | str | None = None,
           right: ArrayLike | str | None = None,
           period: ArrayLike | None = None) -> Array:
  x, xp, fp = util.ensure_arraylike("interp", x, xp, fp)
  if np.shape(xp) != np.shape(fp) or np.ndim(xp) != 1:
    raise ValueError("xp and fp must be one-dimensional arrays of equal size")
  x_arr, xp_arr = util.promote_dtypes_inexact(x, xp)
  fp_arr, = util.promote_dtypes_inexact(fp)
  del x, xp, fp

  if isinstance(left, str):
    if left != 'extrapolate':
      raise ValueError("the only valid string value of `left` is "
                       f"'extrapolate', but got: {left!r}")
    extrapolate_left = True
  else:
    extrapolate_left = False
  if isinstance(right, str):
    if right != 'extrapolate':
      raise ValueError("the only valid string value of `right` is "
                       f"'extrapolate', but got: {right!r}")
    extrapolate_right = True
  else:
    extrapolate_right = False

  if dtypes.issubdtype(x_arr.dtype, np.complexfloating):
    raise ValueError("jnp.interp: complex x values not supported.")

  if period is not None:
    if np.ndim(period) != 0:
      raise ValueError(f"period must be a scalar; got {period}")

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Pass left='extrapolate' exactly, or pass a numeric scalar (e.g. left=-1.0) for a constant fill value
  2. Check for typos in the string
  3. Omit left to get the default fp[0] behavior

Example fix

// before
jnp.interp(x, xp, fp, left='extend')
// after
jnp.interp(x, xp, fp, left='extrapolate')
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(left, str) and left != 'extrapolate':
    raise ValueError("left must be a number or 'extrapolate'")

Type guard

def is_valid_interp_bound(v) -> bool:
    return not isinstance(v, str) or v == 'extrapolate'

Try / catch

catch ValueError and re-raise with caller context showing the offending left value

Prevention

When it happens

Trigger: Calling jnp.interp(x, xp, fp, left='extend'), left='min', left='none', or any non-'extrapolate' string. Numeric left values do not trigger this.

Common situations: Porting NumPy/SciPy interpolation code that used a different sentinel string, or passing None/'None' expecting a null bound; typos like 'extrapolte'.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/1658d1545cc1dc52. Report an issue: GitHub.