{"record":{"id":"f7bbbf48883f2e29","repo":"jax-ml/jax","slug":"nan-policy-is-not-supported","errorCode":null,"errorMessage":"{nan_policy} is not supported","messagePattern":"(.+?) is not supported","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/stats/_core.py","lineNumber":311,"sourceCode":"    ...   jax.scipy.stats.sem(x2)\n    Array([1.73,  nan, 1.53,  nan,  nan,  nan], dtype=float32)\n\n    If ``nan_policy='omit```, ``sem`` omits the ``nan`` values and computes the error\n    for the remaining values along the specified axis.\n\n    >>> with jnp.printoptions(precision=2, suppress=True):\n    ...   jax.scipy.stats.sem(x2, nan_policy='omit')\n    Array([1.73, 1.5 , 1.53, 2.  , 2.5 , 0.5 ], dtype=float32)\n  \"\"\"\n  b, = promote_args_inexact(\"sem\", a)\n  if nan_policy == \"propagate\":\n    size = b.size if axis is None else b.shape[axis]\n    return b.std(axis, ddof=ddof, keepdims=keepdims) / jnp.sqrt(size).astype(b.dtype)\n  elif nan_policy == \"omit\":\n    count = (~jnp.isnan(b)).sum(axis, keepdims=keepdims)\n    return jnp.nanstd(b, axis, ddof=ddof, keepdims=keepdims) / jnp.sqrt(count).astype(b.dtype)\n  else:\n    raise ValueError(f\"{nan_policy} is not supported\")\n","sourceCodeStart":293,"sourceCodeEnd":312,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/stats/_core.py#L293-L312","documentation":"jax.scipy.stats.sem (standard error of the mean) only supports nan_policy values 'propagate' and 'omit'. Any other string raises this error. scipy also supports 'raise', which JAX does not implement because JAX errors must be shape/dtype-static under jit.","triggerScenarios":"Calling jax.scipy.stats.sem(x, nan_policy='raise') or an arbitrary/misspelled string like 'ignore' or 'omit_nan'.","commonSituations":"Copying scipy.stats.sem code that uses nan_policy='raise'; assuming full scipy parameter parity in jax.scipy.","solutions":["Use nan_policy='propagate' (default) or 'omit'","If you need fail-on-NaN behavior, add an explicit jnp.isnan(x).any() check with a Python-side raise before calling sem","Fix typos in the nan_policy string"],"exampleFix":"// before\nse = jax.scipy.stats.sem(x, nan_policy='raise')\n// after\nassert not jnp.isnan(x).any()\nse = jax.scipy.stats.sem(x, nan_policy='propagate')","handlingStrategy":"validation","validationCode":"nan_policy = 'omit'\nassert nan_policy in ('propagate', 'omit')","typeGuard":"def is_supported_nan_policy(p: str) -> bool:\n    return p in ('propagate', 'omit')","tryCatchPattern":"try:\n    sem = jax.scipy.stats.sem(x, nan_policy=p)\nexcept ValueError:\n    sem = jax.scipy.stats.sem(x, nan_policy='propagate')","preventionTips":["Map scipy's 'raise' to an explicit isnan pre-check","Validate nan_policy from config before passing through","Remember JAX errors cannot be data-dependent under jit"],"tags":["jax","scipy","sem","nan-handling"],"backgroundTag":"unsupported-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}