{"record":{"id":"7547f5c6b5809baf","repo":"jax-ml/jax","slug":"cannot-interpret-dtype-as-a-data-type-n-ndid-7547f5","errorCode":null,"errorMessage":"Cannot interpret '{dtype}' as a data type.\\n\\nDid you accidentally write `jax.numpy.empty({shape}, {dtype})` when you meant `jax.numpy.empty(({shape}, {dtype}))`, i.e. with a single tuple argument for the shape?","messagePattern":"Cannot interpret '(.+?)' as a data type\\.\\\\n\\\\nDid you accidentally write `jax\\.numpy\\.empty\\((.+?), (.+?)\\)` when you meant `jax\\.numpy\\.empty\\(\\((.+?), (.+?)\\)\\)`, i\\.e\\. with a single tuple argument for the shape\\?","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/array_creation.py","lineNumber":188,"sourceCode":"    Array of the specified shape and dtype, with the given device/sharding if specified.\n\n  See also:\n    - :func:`jax.lax.empty`\n    - :func:`jax.numpy.empty_like`\n    - :func:`jax.numpy.zeros`\n    - :func:`jax.numpy.ones`\n    - :func:`jax.numpy.full`\n\n  Examples:\n    >>> jnp.empty(4)  # doctest: +SKIP\n    Array([0., 0., 0., 0.], dtype=float32)\n    >>> jnp.empty((2, 3), dtype=bool)  # doctest: +SKIP\n    Array([[False, False, False],\n           [False, False, False]], dtype=bool)\n\n  .. _explicit sharding: https://docs.jax.dev/en/latest/parallel.html\n  \"\"\"\n  if (m := _check_forgot_shape_tuple(\"empty\", shape, dtype)): raise TypeError(m)\n  dtype = dtypes.check_and_canonicalize_user_dtype(\n      float if dtype is None else dtype, \"empty\")\n  shape = canonicalize_shape(shape)\n  if device is not None and out_sharding is None:\n    # lax.empty does not accept SingleDeviceSharding, so we use api.device_put.\n    return api.device_put(lax.empty(shape, dtype), device)\n  else:\n    final_sharding = util.choose_device_or_out_sharding(\n        device, out_sharding, 'jnp.empty')\n    return lax.empty(shape, dtype, out_sharding=final_sharding)\n\n\ndef _check_forgot_shape_tuple(name, shape, dtype) -> str | None:\n  if isinstance(dtype, int) and isinstance(shape, int):\n    return (f\"Cannot interpret '{dtype}' as a data type.\"\n            f\"\\n\\nDid you accidentally write \"\n            f\"`jax.numpy.{name}({shape}, {dtype})` \"\n            f\"when you meant `jax.numpy.{name}(({shape}, {dtype}))`, i.e. \"","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/array_creation.py#L170-L206","documentation":"jnp.empty's guard for the single-tuple typo: jnp.empty((2, 3, jnp.float32)) packs dtype into the shape tuple, causing dtype interpretation to fail; JAX raises with a hint suggesting jnp.empty((shape, dtype)) be written as separate arguments — note empty's unfilled memory means the wrong call silently produces wrong shapes otherwise.","triggerScenarios":"jnp.empty((2, 3, dtype)) — a single tuple containing shape dims plus a dtype element.","commonSituations":"One-line shape/dtype edits with misplaced parentheses; templated array creation code shared across zeros/ones/empty.","solutions":["Split into two arguments: jnp.empty((2, 3), jnp.float32)"],"exampleFix":"# before\na = jnp.empty((2, 3, jnp.float32))\n# after\na = jnp.empty((2, 3), jnp.float32)","handlingStrategy":"validation","validationCode":"assert all(isinstance(d, int) for d in shape), 'shape tuple should contain only ints'","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Split shape and dtype into separate arguments","Check parenthesis placement when editing one-line creation calls"],"tags":["jax","shape-validation","dtype","typo-detection"],"backgroundTag":"invalid-shape-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}