{"record":{"id":"c9c586333c62a696","repo":"jax-ml/jax","slug":"trend-type-must-be-linear-or-constant","errorCode":null,"errorMessage":"Trend type must be 'linear' or 'constant'.","messagePattern":"Trend type must be 'linear' or 'constant'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":530,"sourceCode":"    >>> with jnp.printoptions(precision=3, suppress=True):  # suppress float error\n    ...   print(\"Detrended:\", detrended)\n    ...   print(\"Underlying trend:\", data - detrended)\n    Detrended: [-1. -0.  2. -0. -1.]\n    Underlying trend: [ 2.  4.  6.  8. 10.]\n\n    Removing a constant trend from the data:\n\n    >>> detrended = jax.scipy.signal.detrend(data, type='constant')\n    >>> with jnp.printoptions(precision=3):  # suppress float error\n    ...   print(\"Detrended:\", detrended)\n    ...   print(\"Underlying trend:\", data - detrended)\n    Detrended: [-5. -2.  2.  2.  3.]\n    Underlying trend: [6. 6. 6. 6. 6.]\n  \"\"\"\n  if overwrite_data is not None:\n    raise NotImplementedError(\"overwrite_data argument not implemented.\")\n  if type not in ['constant', 'linear']:\n    raise ValueError(\"Trend type must be 'linear' or 'constant'.\")\n  data_arr, = promote_dtypes_inexact(jnp.asarray(data))\n  if type == 'constant':\n    return data_arr - data_arr.mean(axis, keepdims=True)\n  else:\n    N = data_arr.shape[axis]\n    # bp is static, so we use np operations to avoid pushing to device.\n    bp_arr = np.sort(np.unique(np.r_[0, bp, N]))\n    if bp_arr[0] < 0 or bp_arr[-1] > N:\n      raise ValueError(\"Breakpoints must be non-negative and less than length of data along given axis.\")\n    data_arr = jnp.moveaxis(data_arr, axis, 0)\n    shape = data_arr.shape\n    data_arr = data_arr.reshape(N, -1)\n    for m in range(len(bp_arr) - 1):\n      Npts = bp_arr[m + 1] - bp_arr[m]\n      A = jnp.vstack([\n        jnp.ones(Npts, dtype=data_arr.dtype),\n        jnp.arange(1, Npts + 1, dtype=data_arr.dtype) / Npts.astype(data_arr.dtype)\n      ]).T","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L512-L548","documentation":"detrend's 'type' argument selects the trend model and must be exactly 'linear' or 'constant'. Any other string (including case variants or scipy's alternate spellings) is rejected before any computation.","triggerScenarios":"detrend(x, type='Constant'), type='c', or a typo like 'liner'; feeding type from an unvalidated config string.","commonSituations":"Config-driven preprocessing; porting code that used scipy constants or abbreviations.","solutions":["Use exactly 'linear' or 'constant' (lowercase)","Normalize external strings: type=type.strip().lower() and validate against the allowed pair"],"exampleFix":"// before\njax.scipy.signal.detrend(data, type=cfg['detrend'])\n// after\nt = cfg['detrend'].strip().lower()\nassert t in ('linear', 'constant')\njax.scipy.signal.detrend(data, type=t)","handlingStrategy":"validation","validationCode":"type_ = type_.strip().lower()\nassert type_ in ('linear', 'constant')","typeGuard":"def is_valid_trend_type(t: str) -> bool:\n    return t in ('linear', 'constant')","tryCatchPattern":null,"preventionTips":["Normalize the type string at config load time","Avoid scipy abbreviations; JAX accepts only the two full names"],"tags":["jax","scipy","detrend","invalid-argument-value"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}