jax-ml/jax · error · NotImplementedError
In order to best JIT compile `rankdata`, we cannot know…
Error message
In order to best JIT compile `rankdata`, we cannot know whether `x` contains nans. Please check if nans exist in `x` outside of the `rankdata` function.
What it means
Fires in jax.scipy.stats.rankdata with nan_policy='raise': under JIT the presence of nans in x is a data-dependent property that would require an untraceable conditional, so the check cannot live inside rankdata. The user must test for nans outside the jitted function; the 'omit' policy likewise has unimplemented logic.
Solutions
- Check for NaNs before calling: if jnp.isnan(x).any(): raise ...; then use nan_policy='propagate' or omit the kwarg.
- Move the NaN check to the data-preparation stage of the pipeline.
Example fix
// before jax.scipy.stats.rankdata(x, nan_policy='raise') // after assert not jnp.isnan(x).any(), "x contains NaNs" jax.scipy.stats.rankdata(x) # default: propagate
Defensive patterns
Strategy: validation
Validate before calling
if jnp.isnan(x).any():
raise ValueError("x contains NaNs")
jax.scipy.stats.rankdata(x) Prevention
- Fail fast on NaNs in data prep, not inside stats calls.
- Never pass nan_policy='raise' to jax scipy.stats.
When it happens
Trigger: Calling jax.scipy.stats.rankdata(a, nan_policy='raise') — unconditionally raises, NaNs present or not.
Common situations: Wanting fail-fast NaN semantics inside jitted pipelines; ported scipy code with 'raise' policy.
Related errors
- In order to best JIT compile `mode`, we cannot know whether…
- Logic for `nan_policy` of
- Illegal nan_policy value
- unknown method
- allow_singular argument of multivariate_normal.logpdf
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/bdd6df3e77cb15ad.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/scipy/stats/_core.py:190
Array([1., 3., 2.], dtype=float32)
>>> x = jnp.array([1, 3, 2, 3])
>>> rankdata(x)
Array([1. , 3.5, 2. , 3.5], dtype=float32)
"""
check_arraylike("rankdata", a)
if nan_policy not in ["propagate", "omit", "raise"]:
raise ValueError(
f"Illegal nan_policy value {nan_policy!r}; expected one of "
"{'propagate', 'omit', 'raise'}"
)
if nan_policy == "omit":
raise NotImplementedError(
f"Logic for `nan_policy` of {nan_policy} is not implemented"
)
if nan_policy == "raise":
raise NotImplementedError(
"In order to best JIT compile `rankdata`, we cannot know whether `x` "
"contains nans. Please check if nans exist in `x` outside of the "
"`rankdata` function."
)
if method not in ("average", "min", "max", "dense", "ordinal"):
raise ValueError(f"unknown method '{method}'")
if axis is not None:
return jnp.apply_along_axis(rankdata, axis, a, method)
a = jnp.ravel(a)
out_dtype = dtypes.default_float_dtype()
def _rankdata(a: Array) -> Array:
arr, sorter = lax.sort_key_val(a, jnp.arange(a.size))
inv = invert_permutation(sorter)
View on GitHub (pinned to 1e1c6a8fc0)