{"record":{"id":"b8da4cc762f32655","repo":"jax-ml/jax","slug":"dtype-dtype-is-not-a-valid-jax-array-type-only","errorCode":null,"errorMessage":"Dtype {dtype} is not a valid JAX array type. Only arrays of numeric types are supported by JAX.","messagePattern":"Dtype (.+?) is not a valid JAX array type\\. Only arrays of numeric types are supported by JAX\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":954,"sourceCode":"\n\ndef is_weakly_typed(x: Any) -> bool:\n  if type(x) in _weak_types or type(x) in _registered_weak_types:\n    return True\n  try:\n    return x.aval.weak_type\n  except AttributeError:\n    return False\n\ndef is_weakly_typed_scalar(x: Any) -> bool:\n  try:\n    return x.aval.weak_type and np.ndim(x) == 0\n  except AttributeError:\n    return type(x) in python_scalar_types\n\ndef check_valid_dtype(dtype: DType) -> None:\n  if dtype not in _jax_dtype_set:\n    raise TypeError(f\"Dtype {dtype} is not a valid JAX array \"\n                    \"type. Only arrays of numeric types are supported by JAX.\")\n\ndef _maybe_canonicalize_explicit_dtype(dtype: DType, fun_name: str) -> DType:\n  \"Canonicalizes explicitly requested dtypes, per explicit_x64_dtypes.\"\n  allow = config.explicit_x64_dtypes.value\n  if allow == config.ExplicitX64Mode.ALLOW or config.enable_x64.value:\n    return dtype\n  canonical_dtype = canonicalize_dtype(dtype)\n  if canonical_dtype == dtype:\n    return dtype\n  fun_name = f\" requested in {fun_name}\" if fun_name else \"\"\n  if allow == config.ExplicitX64Mode.ERROR:\n    msg = (\"Explicitly requested dtype {}{} is not available. To enable more \"\n           \"dtypes, set the jax_enable_x64 or allow_explicit_x64_dtypes \"\n           \"configuration options.\"\n          \"See https://github.com/jax-ml/jax#current-gotchas for more.\")\n    msg = msg.format(dtype, fun_name, canonical_dtype.name)\n    raise ValueError(msg)","sourceCodeStart":936,"sourceCodeEnd":972,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L936-L972","documentation":"check_valid_dtype rejects dtypes that are not in JAX's supported set (_jax_dtype_set). JAX only supports numeric (and bool) array element types; this fires when converting a traced/numpy value whose dtype is e.g. object, string, datetime, or a NumPy type JAX does not handle.","triggerScenarios":"Passing np.array(['a','b']) or an object-dtype array to a jnp function; arrays of np.datetime64; np.void/record dtypes; using a custom NumPy dtype subclass when creating ShapedArrays (via _make_shaped_array_for_numpy_array / numpy_scalar paths, e.g. inside jit tracing of constants).","commonSituations":"Accidentally loading a CSV column of strings into an array fed to JAX; object arrays from pandas; mixed-type lists that NumPy upcasts to object dtype.","solutions":["Convert the array to a numeric dtype before passing it: np.asarray(x, dtype=np.float32)","Check x.dtype on the offending input and fix upstream data loading (e.g. pd.to_numeric)","For string data, use a separate tokenizer/encoding step instead of JAX arrays"],"exampleFix":"# before\narr = np.array(['1', '2', '3'])\njnp.sin(arr)\n\n# after\narr = np.array([1, 2, 3], dtype=np.float32)\njnp.sin(arr)","handlingStrategy":"type-guard","validationCode":"import numpy as np\ndef is_jax_numeric(arr) -> bool:\n    return getattr(arr, 'dtype', None) is not None and np.asarray(arr).dtype.kind in 'biufc'","typeGuard":"def has_valid_jax_dtype(x) -> bool:\n    dt = getattr(x, 'dtype', None)\n    return dt is not None and (str(dt) in {'bool','int8','int16','int32','int64','uint8','uint16','uint32','uint64','float16','float32','float64','complex64','complex128'} or dt.kind in 'biufc')","tryCatchPattern":null,"preventionTips":["Coerce inputs with np.asarray(x, dtype=np.float32) at API boundaries","Assert dtype.kind in 'biufc' for user-supplied arrays"],"tags":["jax","dtype","validation","numeric-types"],"backgroundTag":"unsupported-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}