jax-ml/jax · error · TypeError

array() takes at most 5 positional arguments but {len(args)

Error message

array() takes at most 5 positional arguments but {len(args) + 2} were given

What it means

jnp.array's signature only accepts object plus at most three additional positional args (copy, order, ndmin). Passing more raises this TypeError mirroring NumPy's argument-count error, since positional extras cannot be mapped.

Source

Thrown at jax/_src/numpy/array_constructors.py:184

    Constructing JAX arrays from NumPy arrays:

    >>> jnp.array(np.linspace(0, 2, 5))
    Array([0. , 0.5, 1. , 1.5, 2. ], dtype=float32)

    Constructing a JAX array via the Python buffer interface, using Python's
    built-in :mod:`array` module.

    >>> from array import array
    >>> pybuffer = array('i', [2, 3, 5, 7])
    >>> jnp.array(pybuffer)
    Array([2, 3, 5, 7], dtype=int32)

  .. _explicit sharding: https://docs.jax.dev/en/latest/parallel.html
  """
  if args:
    if len(args) > 3:
      raise TypeError(f"array() takes at most 5 positional arguments but {len(args) + 2} were given")

    for i, name in enumerate(["copy", "order", "ndmin"]):
      if i < len(args) and [copy, order, ndmin][i] != [True, "K", 0][i]:
        raise TypeError(f"array() got multiple values for argument '{name}'")
    copy, order, ndmin = (list(args) + [copy, order, ndmin][len(args):])[:3]

    deprecations.warn(
        "jax-array-positional-args",
        "Passing the copy, order, and ndmin arguments to jnp.array positionally "
        "is deprecated. Use keyword arguments instead.",
        stacklevel=2)

  if order is not None and order != "K":
    raise NotImplementedError("Only implemented for order='K'")

  # Fast path: if we're not actually doing any conversion, in many cases we
  # can call lax.stage to lift the value into the trace.
  if dtype is None and device is None and out_sharding is None and ndmin == 0:

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Pass copy, order, ndmin as keyword arguments
  2. Remove the extra positional argument; check the signature of jnp.array in the installed version

Example fix

# before
a = jnp.array(x, True, 'K', 0, 1)
# after
a = jnp.array(x, copy=True, order='K', ndmin=0)
Defensive patterns

Strategy: validation

Validate before calling

# lint/guard: never pass copy/order/ndmin positionally
def safe_array(obj, *, copy=None, order=None, ndmin=0, **kw):
    return jnp.array(obj, copy=copy, order=order, ndmin=ndmin, **kw)

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: jnp.array(obj, True, 'K', 0, extra) — more than 3 positional arguments after object.

Common situations: Code written against NumPy's np.array positional convention migrated to jnp.array with extra positional parameters, or a refactor that splats *args into jnp.array.

Related errors


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