{"record":{"id":"5df8a3907a768b0f","repo":"jax-ml/jax","slug":"np-delete-arr-obj-got-obj-dtype-obj-array-dtyp","errorCode":null,"errorMessage":"np.delete(arr, obj): got obj.dtype={obj_array.dtype}; must be integer or bool.","messagePattern":"np\\.delete\\(arr, obj\\): got obj\\.dtype=(.+?); must be integer or bool\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":7728,"sourceCode":"    obj_array -= arange(len(obj_array), dtype=obj_array.dtype)\n    i = arange(a.shape[axis] - obj_array.size, dtype=obj_array.dtype)\n    i += (i[None, :] >= obj_array[:, None]).sum(0, dtype=i.dtype)\n    return a[(slice(None),) * axis + (i,)]\n\n  # Case 3b: non-unique indices: must be static.\n  obj_array = core.concrete_or_error(np.asarray, obj, \"'obj' array argument of jnp.delete()\")\n  if issubdtype(obj_array.dtype, np.integer):\n    # TODO(jakevdp): in theory this could be done dynamically if obj has no duplicates,\n    # but this would require the complement of lax.gather.\n    mask = np.ones(a.shape[axis], dtype=bool)\n    mask[obj_array] = False\n  elif obj_array.dtype == bool:\n    if obj_array.shape != (a.shape[axis],):\n      raise ValueError(\"np.delete(arr, obj): for boolean indices, obj must be one-dimensional \"\n                       \"with length matching specified axis.\")\n    mask = ~obj_array\n  else:\n    raise ValueError(f\"np.delete(arr, obj): got obj.dtype={obj_array.dtype}; must be integer or bool.\")\n  return a[tuple(slice(None) for i in range(axis)) + (mask,)]\n\n\n@export\ndef insert(arr: ArrayLike, obj: ArrayLike | slice, values: ArrayLike,\n           axis: int | None = None) -> Array:\n  \"\"\"Insert entries into an array at specified indices.\n\n  JAX implementation of :func:`numpy.insert`.\n\n  Args:\n    arr: array object into which values will be inserted.\n    obj: slice or array of indices specifying insertion locations.\n    values: array of values to be inserted.\n    axis: specify the insertion axis in the case of multi-dimensional\n      arrays. If unspecified, ``arr`` will be flattened.\n\n  Returns:","sourceCodeStart":7710,"sourceCodeEnd":7746,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L7710-L7746","documentation":"Raised by jnp.delete when obj (after asarray) has a dtype that is neither integer nor boolean, e.g. float or string. JAX only supports integer positions or boolean masks for deletion; float indices that NumPy might accept via deprecated casting are rejected.","triggerScenarios":"jnp.delete(a, jnp.array([0.5, 1.0])) or passing a Python list of floats; passing a traced/dynamic array with weak dtype that materializes as float_; passing string or complex obj.","commonSituations":"Computing indices with division or np.where output that yields floats (e.g. len(a)/2 instead of len(a)//2); passing np.arange floats; NumPy-to-JAX port where float indices were deprecated-but-working.","solutions":["Cast obj to an integer type: jnp.delete(a, obj.astype(int)) or jnp.array(obj, dtype=int)","Fix upstream index computation to use integer division // or np.round(...).astype(int)","If obj is boolean, keep it boolean — do not let it decay to float"],"exampleFix":"// before\njnp.delete(a, jnp.array([1.0, 2.0]))\n// after\njnp.delete(a, jnp.array([1.0, 2.0], dtype=int))\n","handlingStrategy":"type-guard","validationCode":"obj = jnp.asarray(obj)\nif obj.dtype not in (jnp.bool_) and not jnp.issubdtype(obj.dtype, jnp.integer):\n    obj = obj.astype(jnp.int32)","typeGuard":"def is_valid_delete_obj(obj):\n    o = jnp.asarray(obj)\n    return jnp.issubdtype(o.dtype, jnp.integer) or o.dtype == jnp.bool_","tryCatchPattern":null,"preventionTips":["Use integer division // when computing positions","Always astype(int) float-derived indices","Never rely on NumPy's deprecated float-index tolerance"],"tags":["jax","dtype","indexing"],"backgroundTag":"float-array-index-error","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}