[Numpy-discussion] Style for pad implementation in 'pad' namespace or functions under np.lib

Nathaniel Smith njs@pobox....
Tue Apr 3 02:08:48 CDT 2012

On Mon, Apr 2, 2012 at 7:14 PM, Tim Cera <tim@cerazone.net> wrote:
>> I think the suggestion is pad(a, 5, mode='mean'), which would be
>> consistent with common numpy signatures. The mode keyword should probably
>> have a default, something commonly used. I'd suggest 'mean', Nathaniel
>> suggests 'zero', I think either would be fine.
> I can't type fast enough.  :-)  I should say that I can't type faster than
> Travis since he has already responded....
> Currently that '5' in the example above is the keyword argument 'pad_width'
> which defaults to 1.  So really the only argument then is 'a'?  Everything
> else is keywords?  I missed that in the discussion and I am not sure that it
> is a good idea. In fact as I am typing this I am thinking that we should
> have pad_width as an argument.  I hate to rely on this, because it tends to
> get overused, but 'Explicit is better than implicit.'
> 'pad(a)' would carry a lot of implicit baggage that would mean it would be
> very difficult to figure out what was going on if reading someone else's
> code.  Someone unfamiliar with the pad routine must consult the
> documentation to figure out what 'pad(a)' meant whereas "pad(a, 'mean', 1)",
> regardless of the order of the arguments, would actually read pretty well.
> I defer to a 'consensus' - whatever that might mean, but I am actually
> thinking that the input array, mode/method, and the pad_width should be
> arguments.  The order of the arguments  - I don't care.
> I realize that this thread is around 26 messages long now, but if everyone
> who is interested in this could weigh in one more time about this one issue.
>  To minimize discussion on the list, you can add a comment to the pull
> request at https://github.com/numpy/numpy/pull/242

I guess I'll say
  def pad(arr, width, mode="constant", **kwargs):
Or, if we don't want to have a default argument for mode (and maybe we
don't -- my suggestion of giving it a default was partly based on the
assumption that it was pretty obvious what the default should be!),
then I'm indifferent between
  def pad(arr, width, mode, **kwargs):
  def pad(arr, mode, width, **kwargs):

I definitely don't think width should have a default.

-- Nathaniel

More information about the NumPy-Discussion mailing list