{"record":{"id":"be7fb8795e61b8d5","repo":"jax-ml/jax","slug":"jax-does-not-support-string-indexing-got-idx","errorCode":null,"errorMessage":"JAX does not support string indexing; got {idx=}","messagePattern":"JAX does not support string indexing; got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":91,"sourceCode":"      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(\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","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L73-L109","documentation":"IndexType.from_index raises TypeError when a Python str is used as an index into a JAX array. JAX does not implement NumPy's string/field-based indexing (there are no structured dtypes with named fields). Kept as TypeError (rather than IndexError) only for backward compatibility.","triggerScenarios":"x['field_name'] or x['some_string'] on a jax Array, typically code written for NumPy structured/record arrays.","commonSituations":"Porting NumPy record-array code (arr['names']) to JAX, or accidentally passing a column name/key as an index to a plain jax array.","solutions":["Restructure data: use a dict of separate arrays instead of a structured array","If selecting columns, use an integer column index or slice instead","Keep structured arrays in NumPy and convert plain numeric data to jax"],"exampleFix":"// before\nname = records['name']\n// after\nname = records_dict['name']  # plain dict of jax arrays","handlingStrategy":"validation","validationCode":"if isinstance(idx, str):\n    raise ValueError('use a dict of arrays, not string indexing')","typeGuard":"def is_valid_jax_index(idx) -> bool:\n    return not isinstance(idx, str)","tryCatchPattern":null,"preventionTips":["Store record-like data in dicts of jax arrays","Grep for ['...'] string indexing when porting NumPy record arrays"],"tags":["jax","indexing","string-index"],"backgroundTag":"unsupported-index-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}