{"record":{"id":"fcb3a8849ba030a6","repo":"jax-ml/jax","slug":"jax-numpy-nanquantile-does-not-support-overwrite-i","errorCode":null,"errorMessage":"jax.numpy.nanquantile does not support overwrite_input=True or out != None","messagePattern":"jax\\.numpy\\.nanquantile does not support overwrite_input=True or out != None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":2512,"sourceCode":"    >>> jnp.quantile(x, q)\n    Array([nan, nan, nan], dtype=float32)\n    >>> jnp.nanquantile(x, q)\n    Array([1.5, 3. , 4.5], dtype=float32)\n\n    Computing weighted quantiles while ignoring NaNs:\n\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 \"","sourceCodeStart":2494,"sourceCodeEnd":2530,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L2494-L2530","documentation":"jnp.nanquantile (and nanpercentile/nanmedian via delegation) rejects overwrite_input=True and out != None for the same immutability reasons as quantile: JAX cannot mutate the input or write into a user buffer.","triggerScenarios":"Calling jnp.nanquantile(a, q, overwrite_input=True, out=buf), or ported np.nanmedian(x, overwrite_input=True).","commonSituations":"Porting NaN-aware NumPy statistics code that relied on overwrite_input for large arrays.","solutions":["Drop overwrite_input and out arguments","Rewrite memory-optimization tricks as explicit sort-based preprocessing under jax.jit"],"exampleFix":"// before\nnp.nanquantile(a, 0.5, overwrite_input=True)\n// after\njnp.nanquantile(a, 0.5)","handlingStrategy":"validation","validationCode":"kwargs = dict(overwrite_input=False, out=None)\nq = jnp.nanquantile(a, q, method=method, **{k: v for k, v in kwargs.items() if v})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remove overwrite_input and out when porting nan-quantile APIs","Whitelist supported kwargs in shared stats wrappers"],"tags":["jax","numpy","nanquantile","out-argument","overwrite-input"],"backgroundTag":"unsupported-out-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}