{"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":2473,"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":2455,"sourceCodeEnd":2491,"githubUrl":"https://github.com/numpy/numpy/blob/e117b3ca4edacf581f440dccfd7f3242f0312afa/numpy/_core/fromnumeric.py#L2455-L2491","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nnp.clip(a, 8)        # 8 becomes a_min; a_max missing\n// after\nnp.clip(a, None, 8)  # one-sided upper clip","handlingStrategy":"validation","validationCode":"def safe_clip(a, lo=None, hi=None):\n    # ensure both bounds are explicit (None allowed)\n    import numpy as np\n    if lo is None and hi is None:\n        raise TypeError('clip needs at least one of a_min/a_max')\n    return np.clip(a, lo, hi)","typeGuard":"null","tryCatchPattern":"null","preventionTips":["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)."],"tags":["numpy","clip","argument-validation","bounds"],"analyzedSha":"e117b3ca4edacf581f440dccfd7f3242f0312afa","analyzedAt":"2026-08-07T01:25:31.049Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}