jax-ml/jax · error · ValueError
at least one array or dtype is required
Error message
at least one array or dtype is required
What it means
jax.numpy.result_type() requires at least one argument; calling it with no arguments raises this ValueError. Unlike np.result_type, JAX does not accept an empty argument list.
Source
Thrown at jax/_src/dtypes.py:1097
@overload
def result_type(*args: Any, return_weak_type_flag: Literal[False] = False) -> DType: ...
@overload
def result_type(*args: Any, return_weak_type_flag: bool = False) -> DType | tuple[DType, bool]: ...
@export
def result_type(*args: Any, return_weak_type_flag: bool = False) -> DType | tuple[DType, bool]:
"""Convenience function to apply JAX argument dtype promotion.
Args:
return_weak_type_flag : if True, then return a ``(dtype, weak_type)`` tuple.
If False, just return `dtype`
Returns:
dtype or (dtype, weak_type) depending on the value of the ``return_weak_type`` argument.
"""
if len(args) == 0:
raise ValueError("at least one array or dtype is required")
dtype: DType | ExtendedDType
dtype, weak_type = lattice_result_type(*(default_float_dtype() if arg is None else arg for arg in args))
if weak_type:
dtype = default_types['f' if dtype in _custom_float_dtypes else dtype.kind]()
return (dtype, weak_type) if return_weak_type_flag else dtype
def check_and_canonicalize_user_dtype(
dtype, fun_name=None, *, allow_non_jax_dtypes: bool = False
) -> DType:
"""Checks validity of a user-provided dtype, and returns its canonical form.
For Python scalar types this function returns the corresponding default dtype.
"""
if dtype is None:
raise ValueError("dtype must be specified.")
if isinstance(dtype, Array):
raise ValueError("Passing an array as a dtype argument is no longer "
"supported; instead of dtype=arr use dtype=arr.dtype.")View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Guard the call: if not args: use a sensible default such as jnp.float32
- Require at least one argument in your wrapper and raise your own descriptive error
- Pass jnp.result_type(*arrays) only after checking len(arrays) > 0
Example fix
# before dt = jnp.result_type(*dtypes_list) # crashes when empty # after dt = jnp.result_type(*dtypes_list) if dtypes_list else jnp.float32
Defensive patterns
Strategy: validation
Validate before calling
if not args:
args = [jnp.float32] # or raise your own error
dt = jnp.result_type(*args) Type guard
def has_result_type_args(args) -> bool:
return len(args) > 0 Prevention
- Never call jnp.result_type with *empty spreads; guard *args forwarding
- Unit-test wrapper functions with empty input lists
When it happens
Trigger: jnp.result_type() with zero args, typically from *args forwarding: jnp.result_type(*dtypes) where dtypes is an empty list.
Common situations: Generic wrapper functions that forward a variable-length list of arrays/dtypes which can be empty; refactors where a previously required argument became optional.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- `compute_on`'s compute_type argument must be a string.
- Argument '{x}' of type '{typ}' is not a valid JAX type
- Argument '{arg}' of type {type(arg)} is not a valid JAX type
- Expected kind to be a dtype, string, or tuple; got {kind=}
- dtype must be specified.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/785dce8eacfd3ff4.
Report an issue: GitHub.