{"record":{"id":"c2f9506eaa459055","repo":"jax-ml/jax","slug":"jax-only-supports-number-bool-and-string-dtypes","errorCode":null,"errorMessage":"JAX only supports number, bool, and string dtypes, got dtype {dtype} in {fun_name}","messagePattern":"JAX only supports number, bool, and string dtypes, got dtype (.+?) in (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":1129,"sourceCode":"  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,\n                 output_dtype_or_value: Any) -> bool:\n  \"\"\"Check if a dtype/value is safe to cast to another dtype/value\n\n  Args:\n    input_dtype_or_value: a dtype or value (to be passed to result_type)\n      representing the source dtype.\n    output_dtype_or_value: a dtype or value (to be passed to result_type)\n      representing the target dtype.\n\n  Returns:\n    boolean representing whether the values are safe to cast according to\n    default type promotion semantics.\n\n  Raises:\n    TypePromotionError: if the inputs have differing types and no type promotion","sourceCodeStart":1111,"sourceCodeEnd":1147,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L1111-L1147","documentation":"check_and_canonicalize_user_dtype resolved the requested dtype to a NumPy dtype whose kind is not number/bool/string (e.g. datetime, timedelta, object, void). Unless allow_non_jax_dtypes was enabled, JAX rejects it, naming the operation via fun_name.","triggerScenarios":"dtype=np.dtype('datetime64[ns]') or 'O' passed to ops like conv_general_dilated / searchsorted / sds wrappers; structured dtypes (kind 'V'); timedelta64 inputs from time pipelines.","commonSituations":"Timestamp features not converted to numeric before model code; structured arrays from file I/O (HDF5/npz with compound dtypes) fed into lax ops; passing dtype strings from external schemas.","solutions":["Convert datetimes to numeric: arr.astype('int64') or divide to float seconds","Use numeric/bool/string dtypes only: jnp.float32, jnp.int32, jnp.bool_","Strip structured arrays to their fields: arr['field'].astype('float32')"],"exampleFix":"# before\nlax.conv_general_dilated(..., dtype=np.dtype('datetime64[ns]'))\n\n# after\nlax.conv_general_dilated(..., dtype=jnp.float32)  # after converting data","handlingStrategy":"validation","validationCode":"import numpy as np\nnp_dt = np.dtype(dtype)\nassert np_dt.kind in 'biu b'.replace(' ',''), f'dtype {np_dt} kind {np_dt.kind!r} not allowed'  # numeric/bool\nassert np_dt.kind in 'biu', 'use numeric/bool/string dtypes only'","typeGuard":"def is_allowed_user_dtype(dt) -> bool:\n    import numpy as np\n    try:\n        return np.dtype(dt).kind in 'biuUS'\n    except TypeError:\n        return False","tryCatchPattern":null,"preventionTips":["Convert datetime/timedelta features to int64/float before model code","Destructure structured arrays into their numeric fields early"],"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"}