{"record":{"id":"c435b8a06a432e73","repo":"jax-ml/jax","slug":"invalid-mode-mode-for-np-take","errorCode":null,"errorMessage":"Invalid mode '{mode}' for np.take","messagePattern":"Invalid mode '(.+?)' for np\\.take","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":726,"sourceCode":"    a = a.ravel()\n    axis_idx = 0\n  else:\n    axis_idx = canonicalize_axis(axis, np.ndim(a))\n\n  if mode is None or mode == \"fill\":\n    gather_mode = slicing.GatherScatterMode.FILL_OR_DROP\n    # lax.gather() does not support negative indices, so we wrap them here\n    indices = util._where(indices < 0, indices + a.shape[axis_idx], indices)\n  elif mode == \"raise\":\n    # TODO(phawkins): we have no way to report out of bounds errors yet.\n    raise NotImplementedError(\"The 'raise' mode to jnp.take is not supported.\")\n  elif mode == \"wrap\":\n    indices = ufuncs.mod(indices, lax._const(indices, a.shape[axis_idx]))\n    gather_mode = slicing.GatherScatterMode.PROMISE_IN_BOUNDS\n  elif mode == \"clip\":\n    gather_mode = slicing.GatherScatterMode.CLIP\n  else:\n    raise ValueError(f\"Invalid mode '{mode}' for np.take\")\n\n  index_dims = len(np.shape(indices))\n  slice_sizes = list(np.shape(a))\n  if slice_sizes[axis_idx] == 0:\n    if indices.size != 0:\n      raise IndexError(\"Cannot do a non-empty jnp.take() from an empty axis.\")\n    return a\n\n  if indices.size == 0:\n    out_shape = (slice_sizes[:axis_idx] + list(indices.shape) +\n                 slice_sizes[axis_idx + 1:])\n    return lax.full_like(a, 0, shape=out_shape)\n\n  slice_sizes[axis_idx] = 1\n  dnums = slicing.GatherDimensionNumbers(\n    offset_dims=tuple(\n      list(range(axis_idx)) +\n      list(range(axis_idx + index_dims, len(a.shape) + index_dims - 1))),","sourceCodeStart":708,"sourceCodeEnd":744,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L708-L744","documentation":"jnp.take accepts only modes None/'fill', 'raise' (unimplemented), 'wrap', and 'clip'. Any other string (e.g. 'promiselike', typo) triggers this ValueError.","triggerScenarios":"Calling jnp.take(..., mode='weap') or any unrecognized mode string; passing a mode variable that's None-adjacent or misspelled.","commonSituations":"Typos in mode strings; code parameterizing mode from config where invalid values slip through.","solutions":["Use one of: None, 'fill', 'clip', 'wrap'","Check spelling of the mode string against the docs"],"exampleFix":"// before\ny = jnp.take(a, idx, mode='fills')\n// after\ny = jnp.take(a, idx, mode='fill')","handlingStrategy":"validation","validationCode":"assert mode in (None, 'fill', 'clip', 'wrap'), f'invalid take mode {mode!r}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict mode strings to None/'fill'/'clip'/'wrap'","Centralize mode constants instead of free-form strings"],"tags":["jax","take","invalid-argument","mode"],"backgroundTag":"invalid-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}