{"record":{"id":"2d1e60fe97195d8f","repo":"jax-ml/jax","slug":"cannot-interpret-dtype-as-a-data-type-n-ndid-2d1e60","errorCode":null,"errorMessage":"Cannot interpret '{dtype}' as a data type.\\n\\nDid you accidentally write `jax.numpy.ones({shape}, {dtype})` when you meant `jax.numpy.ones(({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\\.ones\\((.+?), (.+?)\\)` when you meant `jax\\.numpy\\.ones\\(\\((.+?), (.+?)\\)\\)`, 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":138,"sourceCode":"\n  See also:\n    - :func:`jax.numpy.ones_like`\n    - :func:`jax.numpy.empty`\n    - :func:`jax.numpy.zeros`\n    - :func:`jax.numpy.full`\n\n  Examples:\n    >>> jnp.ones(4)\n    Array([1., 1., 1., 1.], dtype=float32)\n    >>> jnp.ones((2, 3), dtype=bool)\n    Array([[ True,  True,  True],\n           [ True,  True,  True]], dtype=bool)\n\n  .. _explicit sharding: https://docs.jax.dev/en/latest/parallel.html\n  \"\"\"\n  if isinstance(shape, types.GeneratorType):\n    raise TypeError(\"expected sequence object with len >= 0 or a single integer\")\n  if (m := _check_forgot_shape_tuple(\"ones\", shape, dtype)): raise TypeError(m)\n  shape = canonicalize_shape(shape)\n  dtype = dtypes.check_and_canonicalize_user_dtype(\n      float if dtype is None else dtype, \"ones\")\n  sharding = util.choose_device_or_out_sharding(\n      device, out_sharding, 'jnp.ones')\n  return lax.full(shape, 1, dtype, sharding=sharding)\n\n\n@export\ndef empty(shape: Any, dtype: DTypeLike | None = None, *,\n          device: xc.Device | Sharding | None = None,\n          out_sharding: NamedSharding | P | None = None) -> Array:\n  \"\"\"Create an empty array.\n\n  JAX implementation of :func:`numpy.empty`. Starting in JAX v0.11.0, this\n  returns an uninitialized array on platforms that support doing so. Prior to\n  v0.11.0, this function returned an array filled with zeros on all platforms.\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/array_creation.py#L120-L156","documentation":"jnp.ones detects the single-tuple typo: jnp.ones((2, 3, jnp.float32)) — shape and dtype packed into one tuple — so the dtype check sees an uninterpretable value and raises with a hint to split them.","triggerScenarios":"jnp.ones((2, 3, dtype)) — one tuple argument mixing shape dims with a dtype.","commonSituations":"Editing or templating shape/dtype on one line and misplacing the parenthesis; porting torch-style size/dtype calls.","solutions":["Pass shape and dtype as separate arguments: jnp.ones((2, 3), jnp.float32)"],"exampleFix":"# before\na = jnp.ones((2, 3, jnp.float32))\n# after\na = jnp.ones((2, 3), jnp.float32)","handlingStrategy":"validation","validationCode":"assert all(isinstance(d, int) for d in shape), 'dtype accidentally inside shape tuple?'","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Separate dtype from shape arguments","Use a linter rule flagging dtype objects inside shape tuples"],"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"}