{"record":{"id":"433e9deeb0bcfc04","repo":"jax-ml/jax","slug":"indexer-must-have-integer-or-boolean-type-got-ind-433e9d","errorCode":null,"errorMessage":"Indexer must have integer or boolean type, got indexer with type {idx_aval.dtype}","messagePattern":"Indexer must have integer or boolean type, got indexer with type (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":101,"sourceCode":"      if dtypes.issubdtype(idx.dtype, np.integer):\n        return cls.ARRAY\n      else:\n        raise TypeError(\n          f\"Indexer must have integer or boolean type, got indexer with type {idx.dtype}\")\n    elif isinstance(idx, str):\n      # TODO(jakevdp): this TypeError is for backward compatibility.\n      # We should switch to IndexError for consistency.\n      raise TypeError(f\"JAX does not support string indexing; got {idx=}\")\n    elif isinstance(idx, Sequence):\n      if not idx:  # empty indices default to float, so special-case this.\n        return cls.ARRAY\n      idx_aval = api.eval_shape(array_constructors.asarray, idx)\n      if idx_aval.dtype == bool:\n        return cls.BOOLEAN\n      elif dtypes.issubdtype(idx_aval.dtype, np.integer):\n        return cls.ARRAY\n      else:\n        raise TypeError(\n          f\"Indexer must have integer or boolean type, got indexer with type {idx_aval.dtype}\")\n    elif isinstance(idx, (float, complex, np.generic)):\n      raise TypeError(\n        f\"Indexer must have integer or boolean type, got indexer with type {np.dtype(type(idx))}\")\n    else:\n      raise IndexError(\"only integers, slices (`:`), ellipsis (`...`), newaxis (`None`)\"\n                       f\" and integer or boolean arrays are valid indices. Got {idx}\")\n\n\nclass ParsedIndex(NamedTuple):\n  \"\"\"Structure for tracking an indexer parsed within the context of an array shape.\"\"\"\n  index: Index\n  typ: IndexType\n  consumed_axes: tuple[int, ...]\n\n\ndef _parse_indices(\n    indices: tuple[Index, ...],","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L83-L119","documentation":"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.","triggerScenarios":"x[[0.0, 1.0]] or x[(1.5, 2.5)] — passing Python lists/tuples of non-integer, non-boolean values as indices.","commonSituations":"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.","solutions":["Make the list elements ints: x[[int(i) for i in idx]] or x[jnp.array(idx, dtype=jnp.int32)]","Use boolean mask lists only if entries are actual booleans","Trace where floats entered the index list and keep that data integral"],"exampleFix":"// before\ny = x[[0.0, 2.0]]\n// after\ny = x[[0, 2]]","handlingStrategy":"validation","validationCode":"if isinstance(idx, (list, tuple)) and idx:\n    assert all(isinstance(i, (bool, np.bool_, int, np.integer)) for i in idx), idx","typeGuard":"def is_int_sequence(seq) -> bool:\n    return all(type(i) is int or (hasattr(i, 'dtype') and np.issubdtype(i.dtype, np.integer) for i in seq)","tryCatchPattern":null,"preventionTips":["Normalize lists to jnp.array(idx, dtype=int) before indexing","Never let division results flow into index lists"],"tags":["jax","indexing","dtype","sequence"],"backgroundTag":"invalid-index-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}