{"record":{"id":"ca3cc1c705e3d9d8","repo":"jax-ml/jax","slug":"method-can-only-be-linear-lower-higher-m","errorCode":null,"errorMessage":"method can only be 'linear', 'lower', 'higher', 'midpoint', 'nearest' or 'inverted_cdf'","messagePattern":"method can only be 'linear', 'lower', 'higher', 'midpoint', 'nearest' or 'inverted_cdf'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":2518,"sourceCode":"\n    >>> x = jnp.array([1, 2, jnp.nan, 4, 5])\n    >>> weights = jnp.array([1, 1, 1, 2, 1])\n    >>> jnp.nanquantile(x, 0.5, weights=weights, method='inverted_cdf')\n    Array(4.0, dtype=float32)\n  \"\"\"\n  a, q = ensure_arraylike(\"nanquantile\", a, q)\n  if weights is not None:\n    weights = ensure_arraylike(\"nanquantile\", weights)\n  if overwrite_input or out is not None:\n    msg = (\"jax.numpy.nanquantile does not support overwrite_input=True or \"\n           \"out != None\")\n    raise ValueError(msg)\n  return _quantile(a, q, axis, method, keepdims, True, weights)\n\ndef _quantile(a: Array, q: Array, axis: int | tuple[int, ...] | None,\n              method: str, keepdims: bool, squash_nans: bool, weights: Array | None = None) -> Array:\n  if method not in [\"linear\", \"lower\", \"higher\", \"midpoint\", \"nearest\", \"inverted_cdf\"]:\n    raise ValueError(\"method can only be 'linear', 'lower', 'higher', 'midpoint', 'nearest' or 'inverted_cdf'\")\n  if weights is not None:\n    if dtypes.issubdtype(weights.dtype, np.complexfloating):\n      raise ValueError(\"Weights cannot be complex types.\")\n    if method != \"inverted_cdf\":\n      raise NotImplementedError(f\"{method} doesn't support weights. Only method 'inverted_cdf' supports weights.\")\n    a, weights = promote_dtypes_inexact(a, weights)\n    if weights.shape != a.shape:\n      if axis is None:\n        raise ValueError(\"Weights shape must match 'a' shape when axis is None.\")\n      ax_tuple = canonicalize_axis_tuple(axis, a.ndim)\n      if weights.shape != tuple(a.shape[ax] for ax in ax_tuple):\n        raise ValueError(f\"Weights shape {weights.shape} must match reduction axes \"\n                          f\"{tuple(a.shape[ax] for ax in ax_tuple)}\")\n      weights = lax.broadcast_in_dim(weights, a.shape, broadcast_dimensions=ax_tuple)\n  else:\n    a, = promote_dtypes_inexact(a)\n  keepdim = []\n  if dtypes.issubdtype(a.dtype, np.complexfloating):","sourceCodeStart":2500,"sourceCodeEnd":2536,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L2500-L2536","documentation":"The method argument of jnp.quantile / jnp.nanquantile must be one of the six supported interpolation/selection methods: linear, lower, higher, midpoint, nearest, inverted_cdf. Anything else — including valid NumPy method names JAX has not implemented — raises ValueError.","triggerScenarios":"Calling jnp.quantile(a, q, method='averaged_inverted_cdf'), method='hazen', 'weibull', 'median_unbiased', 'normal_unbiased', or old interpolation='linear' strings passed as method.","commonSituations":"Using NumPy ≥1.22 method names (many extra methods exist in NumPy but not JAX); copy-pasting scipy.stats.mstats method names; passing the deprecated interpolation kwarg value as method.","solutions":["Switch to one of: 'linear', 'lower', 'higher', 'midpoint', 'nearest', 'inverted_cdf'","For NumPy-only methods like 'median_unbiased', compute with numpy on the host or implement manually","Add a whitelist check in config-driven code to fail fast with a clear message"],"exampleFix":"// before\njnp.quantile(a, q, method='median_unbiased')\n// after\njnp.quantile(a, q, method='nearest')","handlingStrategy":"validation","validationCode":"JAX_QUANTILE_METHODS = {'linear','lower','higher','midpoint','nearest','inverted_cdf'}\nassert method in JAX_QUANTILE_METHODS, f'method must be one of {JAX_QUANTILE_METHODS}'\njnp.quantile(a, q, method=method)","typeGuard":"def is_supported_quantile_method(m: str) -> bool:\n    return m in {'linear','lower','higher','midpoint','nearest','inverted_cdf'}","tryCatchPattern":null,"preventionTips":["Keep a project whitelist of JAX quantile methods","Don't assume NumPy's full method list transfers to JAX","Pin down method strings in configs to avoid free-form input"],"tags":["jax","numpy","quantile","invalid-argument"],"backgroundTag":"unsupported-parameter-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}