{"record":{"id":"9c5773f1a5109791","repo":"jax-ml/jax","slug":"only-integers-slices-ellipsis-new","errorCode":null,"errorMessage":"only integers, slices (`:`), ellipsis (`...`), newaxis (`None`) and integer or boolean arrays are valid indices. Got {idx}","messagePattern":"only integers, slices \\(`:`\\), ellipsis \\(`\\.\\.\\.`\\), newaxis \\(`None`\\) and integer or boolean arrays are valid indices\\. Got (.+?)","errorType":"validation","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":107,"sourceCode":"      # 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, ...],\n    shape: tuple[int, ...],\n) -> list[ParsedIndex]:\n  \"\"\"Parse indices in the context of an array shape.\n\n  Args:\n    indices: a tuple of user-supplied indices to be parsed.","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L89-L125","documentation":"This is the generic fallback IndexError from IndexType.from_index for index objects that are none of: int, slice, ellipsis, None, integer/bool array, integer/bool sequence, or a jax dynamic-slice marker. It matches NumPy's classic message for an unrecognizable index object.","triggerScenarios":"Passing arbitrary objects as indices, e.g. x[some_object], x={'a':1}, or a custom class without __index__; also non-integer np.generic instances reaching the else branch.","commonSituations":"Custom index-like objects, passing dicts/None-like sentinels by mistake, or objects whose __index__ is not defined (e.g. numpy 2.x removed implicit conversion for some types).","solutions":["Convert the object with operator.index() or int() before indexing","If it's a tuple meant as multi-axis indexing, ensure each element is itself a valid index","Check for accidental unpacking/spreading of wrong data into x[...]"],"exampleFix":"// before\ny = x[custom_pos]\n// after\ny = x[int(custom_pos)]","handlingStrategy":"validation","validationCode":"import operator\ntry:\n    operator.index(idx)\nexcept TypeError:\n    raise TypeError(f'invalid index object {idx!r}') from None","typeGuard":"def is_valid_index(obj) -> bool:\n    return obj is None or obj is Ellipsis or isinstance(obj, (slice, int, np.integer)) or hasattr(obj, '__index__')","tryCatchPattern":null,"preventionTips":["Validate third-party objects with operator.index before indexing","Log index types when building dynamic index tuples"],"tags":["jax","indexing","type-error"],"backgroundTag":"unsupported-index-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}