{"record":{"id":"36fbf5bd15e13952","repo":"jax-ml/jax","slug":"unknown-value-for-mode-mode-must-be-one-of-p","errorCode":null,"errorMessage":"Unknown value for mode {mode}, must be one of: ('psd', 'stft')","messagePattern":"Unknown value for mode (.+?), must be one of: \\('psd', 'stft'\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":630,"sourceCode":"  return ext\n\n\ndef _spectral_helper(x: Array, y: ArrayLike | None, fs: ArrayLike = 1.0,\n                     window: str = 'hann', nperseg: int | None = None,\n                     noverlap: int | None = None, nfft: int | None = None,\n                     detrend_type: bool | str | Callable[[Array], Array] = 'constant',\n                     return_onesided: bool = True, scaling: str = 'density',\n                     axis: int = -1, mode: str = 'psd', boundary: str | None = None,\n                     padded: bool = False) -> tuple[Array, Array, Array]:\n  \"\"\"LAX-backend implementation of `scipy.signal._spectral_helper`.\n\n  Unlike the original helper function, `y` can be None for explicitly\n  indicating auto-spectral (non cross-spectral) computation.  In addition to\n  this, `detrend` argument is renamed to `detrend_type` for avoiding internal\n  name overlap.\n  \"\"\"\n  if mode not in ('psd', 'stft'):\n    raise ValueError(f\"Unknown value for mode {mode}, \"\n                     \"must be one of: ('psd', 'stft')\")\n\n  def make_pad(mode, **kwargs):\n    def pad(x, n, axis=-1):\n      pad_width = [(0, 0) for unused_n in range(x.ndim)]\n      pad_width[axis] = (n, n)\n      return jnp.pad(x, pad_width, mode, **kwargs)\n    return pad\n\n  boundary_funcs = {\n      'even': make_pad('reflect'),\n      'odd': odd_ext,\n      'constant': make_pad('edge'),\n      'zeros': make_pad('constant', constant_values=0.0),\n      None: lambda x, *args, **kwargs: x\n  }\n\n  # Check/ normalize inputs","sourceCodeStart":612,"sourceCodeEnd":648,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L612-L648","documentation":"_spectral_helper is the shared engine for csd/stft and dispatches on an internal mode string. Only 'psd' (power-spectral density path, used by csd) and 'stft' are recognized; this is an internal invariant, not a user-facing parameter.","triggerScenarios":"Calling the private _spectral_helper with any mode other than 'psd' or 'stft'. Not reachable through public stft/csd APIs.","commonSituations":"Code that copied jax internals or monkeypatched spectral helpers; very old JAX versions where the helper signature differed.","solutions":["Use the public jax.scipy.signal.stft / csd / welch APIs instead of internals","If you must call the helper, pass mode='psd' or mode='stft' exactly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert mode in ('psd', 'stft')  # internal helper only","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use public stft/csd/welch APIs rather than _spectral_helper","Pin against JAX internal signature changes by wrapping public functions"],"tags":["jax","scipy","internal-api","spectral-analysis"],"backgroundTag":"internal-api-misuse","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}