jax-ml/jax · error · TypeError

Indexer must have integer or boolean type, got indexer with

Error message

Indexer must have integer or boolean type, got indexer with type {idx_aval.dtype}

What it means

When an index is a Python sequence (list/tuple), JAX evaluates its inferred dtype via eval_shape; if that dtype is neither bool nor integer (e.g. a list of floats), this TypeError is raised. JAX will not silently coerce float sequences to integer indices. This mirrors NumPy's deprecation/removal of float indexing.

Source

Thrown at jax/_src/numpy/indexing.py:101

      if dtypes.issubdtype(idx.dtype, np.integer):
        return cls.ARRAY
      else:
        raise TypeError(
          f"Indexer must have integer or boolean type, got indexer with type {idx.dtype}")
    elif isinstance(idx, str):
      # TODO(jakevdp): this TypeError is for backward compatibility.
      # We should switch to IndexError for consistency.
      raise TypeError(f"JAX does not support string indexing; got {idx=}")
    elif isinstance(idx, Sequence):
      if not idx:  # empty indices default to float, so special-case this.
        return cls.ARRAY
      idx_aval = api.eval_shape(array_constructors.asarray, idx)
      if idx_aval.dtype == bool:
        return cls.BOOLEAN
      elif dtypes.issubdtype(idx_aval.dtype, np.integer):
        return cls.ARRAY
      else:
        raise TypeError(
          f"Indexer must have integer or boolean type, got indexer with type {idx_aval.dtype}")
    elif isinstance(idx, (float, complex, np.generic)):
      raise TypeError(
        f"Indexer must have integer or boolean type, got indexer with type {np.dtype(type(idx))}")
    else:
      raise IndexError("only integers, slices (`:`), ellipsis (`...`), newaxis (`None`)"
                       f" and integer or boolean arrays are valid indices. Got {idx}")


class ParsedIndex(NamedTuple):
  """Structure for tracking an indexer parsed within the context of an array shape."""
  index: Index
  typ: IndexType
  consumed_axes: tuple[int, ...]


def _parse_indices(
    indices: tuple[Index, ...],

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Make the list elements ints: x[[int(i) for i in idx]] or x[jnp.array(idx, dtype=jnp.int32)]
  2. Use boolean mask lists only if entries are actual booleans
  3. Trace where floats entered the index list and keep that data integral

Example fix

// before
y = x[[0.0, 2.0]]
// after
y = x[[0, 2]]
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(idx, (list, tuple)) and idx:
    assert all(isinstance(i, (bool, np.bool_, int, np.integer)) for i in idx), idx

Type guard

def is_int_sequence(seq) -> bool:
    return all(type(i) is int or (hasattr(i, 'dtype') and np.issubdtype(i.dtype, np.integer) for i in seq)

Prevention

When it happens

Trigger: x[[0.0, 1.0]] or x[(1.5, 2.5)] — passing Python lists/tuples of non-integer, non-boolean values as indices.

Common situations: Quick interactive indexing with lists that happen to contain floats (e.g. [0.0, 1.0] from earlier computation), or converting coordinates from float pipelines into list indices.

Related errors


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