numpy/numpy · error · TypeError
clip() missing 1 required positional argument: 'a_min'
Error message
clip() missing 1 required positional argument: 'a_min'
What it means
Raised by np.clip when a_max (and/or its alias max) is provided but a_min is missing (left at the np._NoValue sentinel). clip requires both bounds to be resolvable; when only one positional/keyword bound is given, numpy cannot determine a_min and raises this TypeError. Note: passing only min= (the array-API alias) without a_min/a_max is allowed and does not trigger this.
Source
Thrown at numpy/_core/fromnumeric.py:2473
array([1, 1, 2, 3, 4, 5, 6, 7, 8, 8])
>>> np.clip(a, 8, 1)
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
>>> np.clip(a, 3, 6, out=a)
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
>>> a
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.clip(a, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8)
array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8])
"""
if a_min is np._NoValue and a_max is np._NoValue:
a_min = None if min is np._NoValue else min
a_max = None if max is np._NoValue else max
elif a_min is np._NoValue:
raise TypeError("clip() missing 1 required positional "
"argument: 'a_min'")
elif a_max is np._NoValue:
raise TypeError("clip() missing 1 required positional "
"argument: 'a_max'")
elif min is not np._NoValue or max is not np._NoValue:
raise ValueError("Passing `min` or `max` keyword argument when "
"`a_min` and `a_max` are provided is forbidden.")
return _wrapfunc(a, 'clip', a_min, a_max, out=out, **kwargs)
def _sum_dispatcher(a, axis=None, dtype=None, out=None, keepdims=None,
initial=None, where=None):
return (a, out)
# reduction= enables the C fast path for exact-ndarray reductions.
# _ReductionKind selects the appropriate argument signature to use.View on GitHub (pinned to e117b3ca4e)
Solutions
- Pass both bounds: np.clip(a, lo, hi).
- If you only want a one-sided clip, pass None for the unused bound: np.clip(a, None, hi) or np.clip(a, lo, None).
- Remember positional order is (a, a_min, a_max).
Example fix
// before np.clip(a, 8) # 8 becomes a_min; a_max missing // after np.clip(a, None, 8) # one-sided upper clip
Defensive patterns
Strategy: validation
Validate before calling
def safe_clip(a, lo=None, hi=None):
# ensure both bounds are explicit (None allowed)
import numpy as np
if lo is None and hi is None:
raise TypeError('clip needs at least one of a_min/a_max')
return np.clip(a, lo, hi) Type guard
null
Try / catch
null
Prevention
- Always pass both positional bounds (use None for one-sided).
- Remember positional order is (a, a_min, a_max).
- Don't call np.clip(a, single_value).
When it happens
Trigger: np.clip(a, a_max=8); np.clip(a, None is not passed) i.e. calling with a single bound; np.clip(a, max=8) alone is fine (aliases), but np.clip(a, 8) positional treats 8 as a_min and then a_max is missing.
Common situations: Calling clip with a single positional value intending it as the upper bound (it's actually a_min); forgetting the second bound; partial refactor mixing positional and keyword bounds.
Related errors
- clip() missing 1 required positional argument: 'a_max'
- Passing `min` or `max` keyword argument when `a_min` and `a_
- min_digits must be less than or equal to precision
- precision must be greater than 0 if fractional=False
- Can only multiply by integers
AI-assisted analysis of numpy/numpy@e117b3ca4e (2026-08-07).
Data as JSON: /api/errors/709cd0ad52c89d24.
Report an issue: GitHub.