{"record":{"id":"fbc5984185ee8359","repo":"jax-ml/jax","slug":"none-is-not-a-valid-value-for-jnp-array","errorCode":null,"errorMessage":"None is not a valid value for jnp.array","messagePattern":"None is not a valid value for jnp\\.array","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/array_constructors.py","lineNumber":285,"sourceCode":"      backend = xla_bridge.get_backend()\n      if 'rocm' in backend.platform_version.lower():\n        gpu_plugin_extension = rocm_plugin_extension\n      elif 'cuda' in backend.platform_version.lower():\n        gpu_plugin_extension = cuda_plugin_extension\n      else:\n        gpu_plugin_extension = None\n      if gpu_plugin_extension is None:\n        device_id = None\n      else:\n        device_id = gpu_plugin_extension.get_device_ordinal(cai[\"data\"][0])\n      object = _jax.cuda_array_interface_to_buffer(\n          cai=cai, gpu_backend=backend, device_id=device_id)\n\n  # To handle nested lists & tuples, flatten the tree and process each leaf.\n  leaves, treedef = tree_util.tree_flatten(\n      object, is_leaf=lambda x: not isinstance(x, (list, tuple)))\n  if any(leaf is None for leaf in leaves):\n    raise ValueError(\"None is not a valid value for jnp.array\")\n  leaves = [\n      leaf\n      if (leaf_jax_array := getattr(leaf, \"__jax_array__\", None)) is None\n      else leaf_jax_array()\n      for leaf in leaves\n  ]\n  if dtype is None:\n    # Use lattice_result_type rather than result_type to avoid canonicalization.\n    # Otherwise, weakly-typed inputs would have their dtypes canonicalized.\n    try:\n      dtype = (\n          dtypes.lattice_result_type(*leaves)[0]\n          if leaves\n          else dtypes.default_float_dtype()\n      )\n    except TypeError:\n      # This happens if, e.g. one of the entries is a memoryview object.\n      # This is rare, so we only handle it if the normal path fails.","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/array_constructors.py#L267-L303","documentation":"After flattening the input object's pytree structure, jnp.array found a None leaf. JAX treats nested lists/tuples as pytrees and requires every leaf to be a convertible scalar/array; None (Python null) has no numeric representation and unlike some NumPy paths is rejected outright.","triggerScenarios":"jnp.array([1.0, None, 3.0]) or a nested structure containing None, e.g. ragged data with missing values encoded as None.","commonSituations":"Loading JSON/CSV data with missing fields into nested lists, or downstream of a preprocessing step that yields None for absent values.","solutions":["Replace None with a numeric sentinel (np.nan) or filter missing entries before conversion","Convert via NumPy with an explicit dtype after cleaning: np.array(x, dtype=float) after substituting np.nan","Validate leaves with jax.tree_util before calling jnp.array in data pipelines"],"exampleFix":"# before\nimport jax.numpy as jnp\na = jnp.array([1.0, None, 3.0])\n# after\nimport numpy as np, jax.numpy as jnp\na = jnp.array([1.0, np.nan, 3.0])","handlingStrategy":"validation","validationCode":"from jax.tree_util import tree_flatten\nleaves, _ = tree_flatten(obj, is_leaf=lambda x: not isinstance(x, (list, tuple)))\nassert all(l is not None for l in leaves), 'None leaf found'","typeGuard":"def has_no_none_leaves(obj) -> bool:\n    from jax.tree_util import tree_flatten\n    leaves, _ = tree_flatten(obj, is_leaf=lambda x: not isinstance(x, (list, tuple)))\n    return all(l is not None for l in leaves)","tryCatchPattern":"null","preventionTips":["Sanitize missing values to np.nan before array creation","Validate loaded JSON/CSV data leaves in ingestion pipelines"],"tags":["jax","null-handling","data-validation"],"backgroundTag":"null-value-in-input","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}