jax-ml/jax · error · ValueError
Either both or neither of the x and y arguments should be pr
Error message
Either both or neither of the x and y arguments should be provided to jax.numpy.where, got {x} and {y}. What it means
jnp.where requires either only condition (one-arg form) or both x and y (three-arg form). Passing exactly one of x or y is ambiguous and rejected.
Source
Thrown at jax/_src/numpy/lax_numpy.py:2801
>>> jnp.nonzero(x > 4)
(Array([5, 6, 7, 8, 9], dtype=int32),)
When ``x`` and ``y`` are provided, ``where`` selects between them based on
the specified condition:
>>> jnp.where(x > 4, x, 0)
Array([0, 0, 0, 0, 0, 5, 6, 7, 8, 9], dtype=int32)
"""
if x is None and y is None:
util.check_arraylike("where", condition)
return nonzero(condition, size=size, fill_value=fill_value)
else:
util.check_arraylike("where", condition, x, y)
if size is not None or fill_value is not None:
raise ValueError("size and fill_value arguments cannot be used in "
"three-term where function.")
if x is None or y is None:
raise ValueError("Either both or neither of the x and y arguments "
"should be provided to jax.numpy.where, got "
f"{x} and {y}.")
return util._where(condition, x, y)
@export
def select(
condlist: Sequence[ArrayLike],
choicelist: Sequence[ArrayLike],
default: ArrayLike = 0,
) -> Array:
"""Select values based on a series of conditions.
JAX implementation of :func:`numpy.select`, implemented in terms
of :func:`jax.lax.select_n`
Args:
condlist: sequence of array-like conditions. All entries must be mutuallyView on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Supply both x and y: jnp.where(cond, x, 0)
- Or drop both to use the index form: jnp.where(cond)
Example fix
// before jnp.where(cond, x) // after jnp.where(cond, x, 0)
Defensive patterns
Strategy: validation
Validate before calling
if (x is None) != (y is None):
y = 0 if y is None else y # or raise Prevention
- Default both branches explicitly in wrappers: x = 0 if x is None else x
- Lint for where calls with exactly two positional args
When it happens
Trigger: Calling jnp.where(cond, x) or jnp.where(cond, y=0) where the other branch is omitted (e.g. left as default None).
Common situations: Coming from APIs where the else branch defaults to 0 or False; partial refactors that delete one branch; kwargs confusion where x is passed but y forgotten.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Context manager for {state.__name__} config option requires
- size and fill_value arguments cannot be used in three-term w
- No input was provided to the clip function.
- Missing required keyword argument: 'in_sharding'
- Missing required keyword argument: 'in_layouts'
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/4152c54dddd06e13.
Report an issue: GitHub.