pandas-dev/pandas · error · ValueError
invalid validation method '{method}'
Error message
invalid validation method '{method}' What it means
Raised by `CompatValidator.validate` in pandas.compat.numpy.function when the `method` argument is not one of the supported values: `'args'`, `'kwargs'`, or `'both'`. These validators mirror numpy's argument signature validation for methods pandas delegates to numpy (argmin, argmax, etc.). An unknown method indicates a programming error in registering or invoking a validator.
Source
Thrown at pandas/compat/numpy/function.py:93
fname = self.fname if fname is None else fname
max_fname_arg_count = (
self.max_fname_arg_count
if max_fname_arg_count is None
else max_fname_arg_count
)
method = self.method if method is None else method
if method == "args":
validate_args(fname, args, cast("int", max_fname_arg_count), self.defaults)
elif method == "kwargs":
validate_kwargs(fname, kwargs, self.defaults)
elif method == "both":
validate_args_and_kwargs(
fname, args, kwargs, cast("int", max_fname_arg_count), self.defaults
)
else:
raise ValueError(f"invalid validation method '{method}'")
ARGMINMAX_DEFAULTS = {"out": None}
validate_argmin = CompatValidator(
ARGMINMAX_DEFAULTS, fname="argmin", method="both", max_fname_arg_count=1
)
validate_argmax = CompatValidator(
ARGMINMAX_DEFAULTS, fname="argmax", method="both", max_fname_arg_count=1
)
def process_skipna(
skipna: bool | ndarray | None, args: tuple[Any, ...]
) -> tuple[bool, tuple[Any, ...]]:
if isinstance(skipna, ndarray) or skipna is None:
args = (skipna, *args)
skipna = True
View on GitHub (pinned to 3b7651241d)
Solutions
- Use one of the three documented methods: 'args', 'kwargs', or 'both'.
- If you wrote a custom validator, audit the method value passed to `.validate()`.
- Search the codebase for `CompatValidator(` to find the offending registration.
Example fix
// before v = CompatValidator(defaults, fname='op', method='arguments') // after v = CompatValidator(defaults, fname='op', method='args')
Defensive patterns
Strategy: validation
Validate before calling
assert method in {'args', 'kwargs', 'both'}, f'invalid method {method}' Type guard
from typing import Literal ValidMethod = Literal['args', 'kwargs', 'both']
Prevention
- Use the Literal type for method parameters.
- Keep CompatValidator registrations in a single constants module to catch typos.
When it happens
Trigger: Constructing a `CompatValidator(..., method='something')` with an invalid method string; calling `validator.validate(..., method='nope')`. This is essentially only reachable from internal pandas code or plugins extending the numpy-compat layer.
Common situations: Typos in validator registration; downstream libraries subclassing the CompatValidator; pandas internal refactor introducing a new method without updating the dispatch.
Related errors
- numpy operations are not valid with groupby. Use .groupby(..
- `axis` must be fewer than the number of dimensions ({ndim})
- by_row={by_row} not allowed
- No accumulation for {func} implemented on BaseMaskedArray
- No masked accumulation defined for dtype {values.dtype.type}
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/afc2f80189f61eb4.
Report an issue: GitHub.