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.dtype} What it means
JAX's index-type classifier (IndexType.from_index) rejected an array (jax Array or numpy ndarray) used as an index because its dtype is neither integer nor boolean. JAX only supports advanced indexing with integer or boolean arrays; float or other dtypes are rejected before dispatch. The message reports the offending dtype.
Source
Thrown at jax/_src/numpy/indexing.py:86
def from_index(cls, idx: Index) -> IndexType:
"""Create an IndexType enum from a supported JAX array index."""
if idx is None:
return cls.NONE
elif idx is Ellipsis:
return cls.ELLIPSIS
elif isinstance(idx, slice):
return cls.SLICE
elif isinstance(idx, indexing.Slice):
return cls.DYNAMIC_SLICE
elif _is_integer_index(idx):
return cls.INTEGER
elif _is_boolean_index(idx):
return cls.BOOLEAN
elif isinstance(idx, (Array, np.ndarray)):
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(View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Cast the index array to an integer type: x[idx.astype(jnp.int32)]
- Ensure index-producing computations stay integral (use int dtype in arange/zeros/argwhere results)
- If the values are truth values, use a boolean mask instead: x[idx > 0]
Example fix
// before sel = jnp.array([0.5, 1.5]) y = x[sel] // after sel = jnp.array([0, 1]) y = x[sel]
Defensive patterns
Strategy: type-guard
Validate before calling
def is_valid_index_dtype(a):
return jnp.issubdtype(jnp.asarray(a).dtype, jnp.integer) or jnp.asarray(a).dtype == jnp.bool_ Type guard
def is_int_index(idx) -> bool:
a = jnp.asarray(idx)
return jnp.issubdtype(a.dtype, jnp.integer) Prevention
- Always create index arrays with explicit dtype=jnp.int32/int64
- Assert index dtype before indexing in data-pipeline code
When it happens
Trigger: Passing a float (or otherwise non-integer/boolean) Array/ndarray as an index, e.g. x[jnp.asarray([0.5, 1.5])] or x[np.array([1.0, 2.0])], inside x[...] on any jax array.
Common situations: Index arrays produced by arithmetic that upcasts to float (e.g. jnp.arange/2), indices loaded from float data, or metrics like argmax results converted through float ops. Common when porting NumPy code that happened to tolerate float indices.
Related errors
- Indexer must have integer or boolean type, got indexer with
- Indexer must have integer or boolean type, got indexer with
- np.delete(arr, obj): got obj.dtype={obj_array.dtype}; must b
- jnp.insert(): index array must be integer typed; got {obj}
- Cannot commute unswizzle and indexer with {aval}, which does
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/45af7d1ad0494cf0.
Report an issue: GitHub.