numpy 1.9b1 bug in pad function?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

numpy 1.9b1 bug in pad function?

Nadav Horesh



In [1]: import numpy as np
In [2]: a = np.arange(4)
In [3]: np.pad(a,2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-f56fe53684b8> in <module>()
----> 1 np.pad(a,2)

/usr/lib64/python3.3/site-packages/numpy/lib/arraypad.py in pad(array, pad_width, mode, **kwargs)
   1331     elif mode is None:
   1332         raise ValueError('Keyword "mode" must be a function or one of %s.' %
-> 1333                          (list(allowedkwargs.keys()),))
   1334     else:
   1335         # Drop back to old, slower np.apply_along_axis mode for user-supplied

ValueError: Keyword "mode" must be a function or one of ['edge', 'constant', 'wrap', 'reflect', 'median', 'maximum', 'minimum', 'symmetric', 'linear_ramp', 'mean'].

In [4]: np.__version__
Out[4]: '1.9.0b1'

The documentation specify that the mode parameter is optional

I am getting the same for both python 2.7 and 3.3
OS: Gentoo linux

   Nadav

 
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy 1.9b1 bug in pad function?

Stéfan van der Walt
Hi Nadav

On Sat, Jun 14, 2014 at 8:11 AM, Nadav Horesh <[hidden email]> wrote:
> In [4]: np.__version__
> Out[4]: '1.9.0b1'
>
> The documentation specify that the mode parameter is optional

I don't see the optional specification in the docstring.  Perhaps
because mode=None in the signature?

The reason is that then, if you do not specify the signature (as in
your case), you get the following helpful message:

ValueError: Keyword "mode" must be a function or one of ['reflect',
'linear_ramp', 'edge', 'constant', 'minimum', 'wrap', 'symmetric',
'median', 'maximum', 'mean'].

Instead of

pad() takes exactly 3 arguments (2 given)

Regards
Stéfan
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy 1.9b1 bug in pad function?

Nadav Horesh
This is most likely a documentation error since:



In [7]: np.pad(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-7a0346d77134> in <module>()
----> 1 np.pad(a)

TypeError: pad() missing 1 required positional argument: 'pad_width'


Nadav
________________________________________
From: [hidden email] <[hidden email]> on behalf of Stéfan van der Walt <[hidden email]>
Sent: 14 June 2014 13:39
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] numpy 1.9b1 bug in pad function?

Hi Nadav

On Sat, Jun 14, 2014 at 8:11 AM, Nadav Horesh <[hidden email]> wrote:
> In [4]: np.__version__
> Out[4]: '1.9.0b1'
>
> The documentation specify that the mode parameter is optional

I don't see the optional specification in the docstring.  Perhaps
because mode=None in the signature?

The reason is that then, if you do not specify the signature (as in
your case), you get the following helpful message:

ValueError: Keyword "mode" must be a function or one of ['reflect',
'linear_ramp', 'edge', 'constant', 'minimum', 'wrap', 'symmetric',
'median', 'maximum', 'mean'].

Instead of

pad() takes exactly 3 arguments (2 given)

Regards
Stéfan
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy 1.9b1 bug in pad function?

Stéfan van der Walt
On 2014-06-14 14:40:29, Nadav Horesh <[hidden email]> wrote:
> This is most likely a documentation error since:
>
> In [7]: np.pad(a)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-7-7a0346d77134> in <module>()
> ----> 1 np.pad(a)
>
> TypeError: pad() missing 1 required positional argument: 'pad_width'

That is because the signature is

pad(array, pad_width, mode=None, ...)

But mode *does* need to be specified.  I see why this can be confusing,
though, so perhaps we should simply make mode a positional argument too.

Stéfan
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: numpy 1.9b1 bug in pad function?

Stéfan van der Walt
In reply to this post by Nadav Horesh
On 2014-06-14 14:40:29, Nadav Horesh <[hidden email]> wrote:
> TypeError: pad() missing 1 required positional argument: 'pad_width'

I've added a PR here for further discussion:

https://github.com/numpy/numpy/pull/4808

Stéfan
_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion