{"record":{"id":"709cd0ad52c89d24","repo":"numpy/numpy","slug":"clip-missing-1-required-positional-argument-a","errorCode":null,"errorMessage":"clip() missing 1 required positional argument: 'a_min'","messagePattern":"clip\\(\\) missing 1 required positional argument: 'a_min'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"numpy/_core/fromnumeric.py","lineNumber":2444,"sourceCode":"    array([1, 1, 2, 3, 4, 5, 6, 7, 8, 8])\n    >>> np.clip(a, 8, 1)\n    array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])\n    >>> np.clip(a, 3, 6, out=a)\n    array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])\n    >>> a\n    array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])\n    >>> a = np.arange(10)\n    >>> a\n    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n    >>> np.clip(a, [3, 4, 1, 1, 1, 4, 4, 4, 4, 4], 8)\n    array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8])\n\n    \"\"\"\n    if a_min is np._NoValue and a_max is np._NoValue:\n        a_min = None if min is np._NoValue else min\n        a_max = None if max is np._NoValue else max\n    elif a_min is np._NoValue:\n        raise TypeError(\"clip() missing 1 required positional \"\n                        \"argument: 'a_min'\")\n    elif a_max is np._NoValue:\n        raise TypeError(\"clip() missing 1 required positional \"\n                        \"argument: 'a_max'\")\n    elif min is not np._NoValue or max is not np._NoValue:\n        raise ValueError(\"Passing `min` or `max` keyword argument when \"\n                         \"`a_min` and `a_max` are provided is forbidden.\")\n\n    return _wrapfunc(a, 'clip', a_min, a_max, out=out, **kwargs)\n\n\ndef _sum_dispatcher(a, axis=None, dtype=None, out=None, keepdims=None,\n                    initial=None, where=None):\n    return (a, out)\n\n\n# reduction= enables the C fast path for exact-ndarray reductions.\n# _ReductionKind selects the appropriate argument signature to use.","sourceCodeStart":2426,"sourceCodeEnd":2462,"githubUrl":"https://github.com/numpy/numpy/blob/44f1f77dd85fd0b91f9f0329f0f012f99bd3f3d6/numpy/_core/fromnumeric.py#L2426-L2462","documentation":"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'.","triggerScenarios":"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').","commonSituations":"Migrating old code that used np.clip(a, min=None, max=10); partial migration that mixes conventions; calling clip with only an upper bound.","solutions":["To clip only the upper bound, pass a_min=None explicitly: np.clip(a, None, 10).","Use the legacy kwargs consistently: np.clip(a, min=None, max=10) (and do not also pass a_min/a_max).","Audit call sites for partial bounds and supply both arguments or use None explicitly."],"exampleFix":"// before\nnp.clip(a, a_max=10)   # a_min left as _NoValue -> TypeError\n// after\nnp.clip(a, None, 10)   # explicit None = no lower bound","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef clip_safe(a, a_min=None, a_max=None):\n    # Resolve to explicit None instead of np._NoValue to mean 'no bound'.\n    if a_min is None and a_max is None:\n        raise TypeError('at least one of a_min, a_max must be non-None')\n    return np.clip(a, a_min, a_max)\n\nclip_safe(a, None, 10)   # upper-bound only","typeGuard":"def has_explicit_a_min(a_min) -> bool:\n    import numpy as np\n    return a_min is not np._NoValue and a_min is not None or a_min is None","tryCatchPattern":"try:\n    np.clip(a, a_max=10)\nexcept TypeError as e:\n    if \"missing 1 required positional argument: 'a_min'\" in str(e):\n        np.clip(a, None, 10)\n    else:\n        raise","preventionTips":["Always pass a_min positionally even when only upper bound is intended (use None).","Audit old min=/max= call sites during numpy upgrades.","Wrap np.clip in a helper that normalises (None, value) explicitly."],"tags":["numpy","clip","argument-validation","api-migration"],"backgroundTag":null,"analyzedSha":"44f1f77dd85fd0b91f9f0329f0f012f99bd3f3d6","analyzedAt":"2026-08-11T21:31:04.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}