jax-ml/jax · error · ValueError
the only valid string value of `right` is 'extrapolate', but
Error message
the only valid string value of `right` is 'extrapolate', but got: {right!r} What it means
jnp.interp accepts the special string 'extrapolate' for the right argument (to extrapolate above the last xp point). Any other string is rejected; only 'extrapolate' or a numeric bound is valid.
Source
Thrown at jax/_src/numpy/lax_numpy.py:2615
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}")
period = ufuncs.abs(period)
x_arr = x_arr % period
xp_arr = xp_arr % period
xp_arr, fp_arr = lax.sort_key_val(xp_arr, fp_arr)
xp_arr = concatenate([xp_arr[-1:] - period, xp_arr, xp_arr[:1] + period])
fp_arr = concatenate([fp_arr[-1:], fp_arr, fp_arr[:1]])
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use right='extrapolate' or a numeric scalar
- Fix string typos
- Leave right unset for the default fp[-1] behavior
Example fix
// before jnp.interp(x, xp, fp, right='extrapolte') // after jnp.interp(x, xp, fp, right='extrapolate')
Defensive patterns
Strategy: validation
Validate before calling
if isinstance(right, str) and right != 'extrapolate':
right = 'extrapolate' # or raise Type guard
def is_valid_interp_bound(v) -> bool:
return not isinstance(v, str) or v == 'extrapolate' Try / catch
catch ValueError, fall back to numeric bound or default
Prevention
- Use typing.Literal['extrapolate'] in wrappers to get static checking
- Centralize interp kwargs in one config object
When it happens
Trigger: Calling jnp.interp(x, xp, fp, right='extend') or any non-'extrapolate' string for right.
Common situations: Migrating SciPy np.interp-style code with custom sentinel strings; copy-paste from codebases that use different extrapolation flags.
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
- the only valid string value of `left` is 'extrapolate', but
- Unknown resize method "{s}"
- Use 'cuda', 'rocm', or 'oneapi' for lax.platform_dependent.
- 'trans' value must be 0, 1, or 2, got {trans}
- Got unexpected `to` value. Allowed `to` values are: {_allowe
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/906dd8130d215d87.
Report an issue: GitHub.