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

np.clip was migrated from keyword arguments (min=, max=) to positional a_min, a_max. If a caller supplies a_max (positionally or by name) but leaves a_min at its _NoValue sentinel, numpy detects the asymmetric usage and raises TypeError telling you a_min is missing, rather than silently treating None as 'no lower bound'.

Solutions

  1. To clip only the upper bound, pass a_min=None explicitly: np.clip(a, None, 10).
  2. Use the legacy kwargs consistently: np.clip(a, min=None, max=10) (and do not also pass a_min/a_max).
  3. Audit call sites for partial bounds and supply both arguments or use None explicitly.

Example fix

// before
np.clip(a, a_max=10)   # a_min left as _NoValue -> TypeError
// after
np.clip(a, None, 10)   # explicit None = no lower bound
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np

def clip_safe(a, a_min=None, a_max=None):
    # Resolve to explicit None instead of np._NoValue to mean 'no bound'.
    if a_min is None and a_max is None:
        raise TypeError('at least one of a_min, a_max must be non-None')
    return np.clip(a, a_min, a_max)

clip_safe(a, None, 10)   # upper-bound only

Type guard

def has_explicit_a_min(a_min) -> bool:
    import numpy as np
    return a_min is not np._NoValue and a_min is not None or a_min is None

Try / catch

try:
    np.clip(a, a_max=10)
except TypeError as e:
    if "missing 1 required positional argument: 'a_min'" in str(e):
        np.clip(a, None, 10)
    else:
        raise

Prevention

When it happens

Trigger: np.clip(a, a_max=10); np.clip(a, None, 10) where None was intended as no lower bound (the new API uses np._NoValue, not None, for 'omitted').

Common situations: Migrating old code that used np.clip(a, min=None, max=10); partial migration that mixes conventions; calling clip with only an upper bound.

Related errors


AI-assisted analysis of numpy/numpy@44f1f77dd8 (2026-08-11). Data as JSON: /api/errors/709cd0ad52c89d24. Report an issue: GitHub.

Appendix: source

Thrown at numpy/_core/fromnumeric.py:2444

    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 44f1f77dd8)