[Numpy-discussion] Rename arguments to np.clip and np.put

Allan Haldane allanhaldane at gmail.com
Mon Mar 30 18:59:34 EDT 2015

Hello everyone,

What does the list think of renaming the arguments of np.clip and np.put
to match those of ndarray.clip/put? Currently the signatures are

    np.clip(a, a_min, a_max, out=None)
    ndarray.clip(a, min=None, max=None, out=None)

    np.put(a, ind, v, mode='raise')
    ndarray.put(indices, values, mode='raise')

(The docstring for ndarray.clip is incorrect, too).

I suggest the signatures might be changed to this:

    np.clip(a, min=None, max=None, out=None, **kwargs)
    np.put(a, indices, values, mode='raise')

We can still take care of the old argument names for np.clip using
**kwards, while showing a deprecation warning. I think that would be
fully back-compatible. Note this makes np.clip more flexible as only one
of min or max are needed now, just like ndarray.clip.

np.put is trickier to keep back-compatible as it has two positional
arguments. Someone who called `np.put(a, v=0, ind=1)` would be in
trouble with this change, although I didn't find anyone on github doing
so. I suppose to maintain back-compatibility we could make indices and
values keyword args, and use the same kwargs trick as in np.clip, but
that might be confusing since they're both required args.

Any opinions or suggestions?


More information about the NumPy-Discussion mailing list