{"record":{"id":"633431c26e77c0e1","repo":"jax-ml/jax","slug":"passing-an-array-as-a-dtype-argument-is-no-longer","errorCode":null,"errorMessage":"Passing an array as a dtype argument is no longer supported; instead of dtype=arr use dtype=arr.dtype.","messagePattern":"Passing an array as a dtype argument is no longer supported; instead of dtype=arr use dtype=arr\\.dtype\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":1114,"sourceCode":"  if len(args) == 0:\n    raise ValueError(\"at least one array or dtype is required\")\n  dtype: DType | ExtendedDType\n  dtype, weak_type = lattice_result_type(*(default_float_dtype() if arg is None else arg for arg in args))\n  if weak_type:\n    dtype = default_types['f' if dtype in _custom_float_dtypes else dtype.kind]()\n  return (dtype, weak_type) if return_weak_type_flag else dtype\n\ndef check_and_canonicalize_user_dtype(\n    dtype, fun_name=None, *, allow_non_jax_dtypes: bool = False\n) -> DType:\n  \"\"\"Checks validity of a user-provided dtype, and returns its canonical form.\n\n  For Python scalar types this function returns the corresponding default dtype.\n  \"\"\"\n  if dtype is None:\n    raise ValueError(\"dtype must be specified.\")\n  if isinstance(dtype, Array):\n    raise ValueError(\"Passing an array as a dtype argument is no longer \"\n                     \"supported; instead of dtype=arr use dtype=arr.dtype.\")\n  if issubdtype(dtype, extended):\n    return dtype\n  # Avoid using `dtype in [...]` because of numpy dtype equality overloading.\n  if isinstance(dtype, type) and (f := _DEFAULT_TYPEMAP.get(dtype)) is not None:\n    return f()\n  np_dtype = np.dtype(dtype)\n  if np_dtype not in _jax_dtype_set:\n    if allow_non_jax_dtypes:\n      return np_dtype\n    msg = (\n        f'JAX only supports number, bool, and string dtypes, got dtype {dtype}'\n    )\n    msg += f\" in {fun_name}\" if fun_name else \"\"\n    raise TypeError(msg)\n  return _maybe_canonicalize_explicit_dtype(np_dtype, fun_name or \"\")\n\ndef safe_to_cast(input_dtype_or_value: Any,","sourceCodeStart":1096,"sourceCodeEnd":1132,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L1096-L1132","documentation":"Older JAX versions accepted a 0-d array as the dtype= argument (using its value as a dtype code); this was removed. Passing a jax.Array (e.g. jnp.int32(0) or np.array(3)) as dtype now raises immediately with a hint to use arr.dtype instead.","triggerScenarios":"dtype=jnp.array(3), dtype=np.array('float32'), or forwarding a computed scalar array into a dtype= kwarg of ops routed through check_and_canonicalize_user_dtype (conv_general_dilated, searchsorted, sds functions, etc.).","commonSituations":"Legacy code or tutorials written for old JAX; dynamically-built dtype arguments stored as arrays; copy-paste from NumPy where np.dtype(np.array(...)) sometimes worked.","solutions":["Use the dtype class: dtype=jnp.int32 / np.float32","Use the array's dtype attribute: dtype=arr.dtype","If selecting from a registry, store dtype objects/classes, not arrays"],"exampleFix":"# before\nop(..., dtype=jnp.array(7))  # old-style numeric dtype code\n\n# after\nop(..., dtype=jnp.int32)","handlingStrategy":"type-guard","validationCode":"from jax import Array\nif isinstance(dtype, Array):\n    dtype = dtype.dtype\nop(..., dtype=dtype)","typeGuard":"import numpy as np\nfrom jax import Array\n\ndef is_valid_dtype_arg(dt: object) -> bool:\n    return not isinstance(dt, Array) and not isinstance(dt, np.ndarray)","tryCatchPattern":null,"preventionTips":["Store dtypes as classes/np.dtype objects, never as arrays","Run a lint/grep for dtype=np.array / dtype=jnp.array in legacy code before upgrading JAX"],"tags":["jax","dtype","api-removal","migration"],"backgroundTag":"deprecated-api-usage","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}