{"record":{"id":"45af7d1ad0494cf0","repo":"jax-ml/jax","slug":"indexer-must-have-integer-or-boolean-type-got-ind","errorCode":null,"errorMessage":"Indexer must have integer or boolean type, got indexer with type {idx.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":86,"sourceCode":"  def from_index(cls, idx: Index) -> IndexType:\n    \"\"\"Create an IndexType enum from a supported JAX array index.\"\"\"\n    if idx is None:\n      return cls.NONE\n    elif idx is Ellipsis:\n      return cls.ELLIPSIS\n    elif isinstance(idx, slice):\n      return cls.SLICE\n    elif isinstance(idx, indexing.Slice):\n      return cls.DYNAMIC_SLICE\n    elif _is_integer_index(idx):\n      return cls.INTEGER\n    elif _is_boolean_index(idx):\n      return cls.BOOLEAN\n    elif isinstance(idx, (Array, np.ndarray)):\n      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(","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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]"],"exampleFix":"// before\nsel = jnp.array([0.5, 1.5])\ny = x[sel]\n// after\nsel = jnp.array([0, 1])\ny = x[sel]","handlingStrategy":"type-guard","validationCode":"def is_valid_index_dtype(a):\n    return jnp.issubdtype(jnp.asarray(a).dtype, jnp.integer) or jnp.asarray(a).dtype == jnp.bool_","typeGuard":"def is_int_index(idx) -> bool:\n    a = jnp.asarray(idx)\n    return jnp.issubdtype(a.dtype, jnp.integer)","tryCatchPattern":null,"preventionTips":["Always create index arrays with explicit dtype=jnp.int32/int64","Assert index dtype before indexing in data-pipeline code"],"tags":["jax","indexing","dtype"],"backgroundTag":"invalid-index-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}