{"record":{"id":"4dee5dd22b946762","repo":"jax-ml/jax","slug":"illegal-nan-policy-value-nan-policy-r-expected","errorCode":null,"errorMessage":"Illegal nan_policy value {nan_policy!r}; expected one of {'propagate', 'omit', 'raise'}","messagePattern":"Illegal nan_policy value (.+?); expected one of (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/stats/_core.py","lineNumber":91,"sourceCode":"    (Array([1, 3, 2], dtype=int32), Array([3, 3, 3], dtype=int32))\n\n    By default, ``jax.scipy.stats.mode`` reduces the dimension of the result.\n    To keep the dimensions same as that of the input array, the argument\n    ``keepdims`` must be set to ``True``.\n\n    >>> mode, count = jax.scipy.stats.mode(x1, axis=1, keepdims=True)\n    >>> mode, count\n    (Array([[1],\n           [3],\n           [2]], dtype=int32), Array([[3],\n           [3],\n           [3]], dtype=int32))\n  \"\"\"\n  check_arraylike(\"mode\", a)\n  x = jnp.atleast_1d(a)\n\n  if nan_policy not in [\"propagate\", \"omit\", \"raise\"]:\n    raise ValueError(\n      f\"Illegal nan_policy value {nan_policy!r}; expected one of \"\n      \"{'propagate', 'omit', 'raise'}\"\n    )\n  if nan_policy == \"omit\":\n    # TODO: return answer without nans included.\n    raise NotImplementedError(\n      f\"Logic for `nan_policy` of {nan_policy} is not implemented\"\n    )\n  if nan_policy == \"raise\":\n    raise NotImplementedError(\n      \"In order to best JIT compile `mode`, we cannot know whether `x` contains nans. \"\n      \"Please check if nans exist in `x` outside of the `mode` function.\"\n    )\n  if axis is not None:\n    axis = canonicalize_axis(axis, x.ndim)\n\n  input_shape = x.shape\n  if keepdims:","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/stats/_core.py#L73-L109","documentation":"jax.scipy.stats.mode validates its nan_policy keyword and only accepts 'propagate', 'omit', or 'raise'; any other string raises this ValueError. This mirrors scipy's API surface but is enforced eagerly at call time in JAX.","triggerScenarios":"Calling jax.scipy.stats.mode(a, nan_policy='skip') or a typo like 'raises', 'Propagate', or None.","commonSituations":"Copy-pasted scipy code using older/newer policy names; passing an uninitialized variable (None) as nan_policy.","solutions":["Use one of the exact strings 'propagate', 'omit', or 'raise' (lowercase).","Note that 'omit' and 'raise' themselves raise NotImplementedError in jax — effectively only 'propagate' works; prefer removing the kwarg or handling NaNs before the call."],"exampleFix":"// before\njax.scipy.stats.mode(x, nan_policy='skip')\n\n// after\njax.scipy.stats.mode(x, nan_policy='propagate')","handlingStrategy":"validation","validationCode":"assert nan_policy in ('propagate', 'omit', 'raise'), f\"bad nan_policy: {nan_policy!r}\"","typeGuard":"def is_valid_nan_policy(p) -> bool:\n    return isinstance(p, str) and p in ('propagate', 'omit', 'raise')","tryCatchPattern":"try:\n    jax.scipy.stats.mode(x, nan_policy=p)\nexcept ValueError as e:\n    if 'Illegal nan_policy' in str(e):\n        jax.scipy.stats.mode(x)  # fallback to default\n    else:\n        raise","preventionTips":["Centralize nan_policy constants instead of free-form strings.","Remember only 'propagate' is implemented in jax."],"tags":["jax","scipy","stats","mode","nan-policy","argument-validation"],"backgroundTag":"scipy-nan-policy-unsupported","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}