jax-ml/jax · error · ValueError
unknown method '{method}'
Error message
unknown method '{method}' What it means
jax.scipy.stats.rankdata only supports the tie-handling methods 'average', 'min', 'max', 'dense', and 'ordinal'; any other method string raises ValueError.
Source
Thrown at jax/_src/scipy/stats/_core.py:197
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)
if method == "ordinal":
return (inv + 1).astype(out_dtype)
obs = jnp.concatenate([jnp.array([True]), arr[1:] != arr[:-1]])
dense = obs.cumsum()[inv]
if method == "dense":
return dense.astype(out_dtype)
count = jnp.nonzero(obs, size=arr.size + 1, fill_value=obs.size)[0].astype(out_dtype)View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use one of: 'average', 'min', 'max', 'dense', 'ordinal' (exact lowercase).
- If you need pandas-style 'first'/'min' with ordering semantics, implement via argsort or use scipy.stats.rankdata directly.
Example fix
// before jax.scipy.stats.rankdata(x, method='first') // after jax.scipy.stats.rankdata(x, method='ordinal')
Defensive patterns
Strategy: validation
Validate before calling
VALID = ('average', 'min', 'max', 'dense', 'ordinal')
assert method in VALID, f"method must be one of {VALID}, got {method!r}" Type guard
def is_valid_rank_method(m) -> bool:
return m in ('average', 'min', 'max', 'dense', 'ordinal') Try / catch
try:
jax.scipy.stats.rankdata(x, method=method)
except ValueError as e:
if 'unknown method' in str(e):
jax.scipy.stats.rankdata(x, method='average')
else:
raise Prevention
- Validate config-driven method strings at load time.
- Note pandas 'first' has no jax/scipy equivalent; use 'ordinal'.
When it happens
Trigger: Calling jax.scipy.stats.rankdata(a, method='dense ') with whitespace/typo, or an unsupported method name.
Common situations: Passing method from a config dict with a typo; assuming a scipy method name like 'first' (pandas rank style) exists.
Related errors
- Illegal nan_policy value {nan_policy!r}; expected one of {'p
- In order to best JIT compile `rankdata`, we cannot know whet
- ind must be a positive integer; got {ind=}
- Expected kind to be on of: {valid_kind}; got {kind}
- Expected kind to be one of: {valid_kind}; got {kind}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/00e01cbb30a3ecdc.
Report an issue: GitHub.