[Numpy-discussion] numpy histogram normed=True (bug / confusing behavior)

Ralf Gommers ralf.gommers@googlemail....
Tue Aug 31 09:27:10 CDT 2010

On Tue, Aug 31, 2010 at 10:13 PM, David Huard <david.huard@gmail.com> wrote:

> On Tue, Aug 31, 2010 at 7:02 AM, Ralf Gommers <ralf.gommers@googlemail.com
> > wrote:
>> On Tue, Aug 31, 2010 at 3:44 AM, David Huard <david.huard@gmail.com>wrote:
>>> I just added a warning alerting concerned users (r8674), so this takes
>>> care of the bug fix and Nils wish to avoid a silent change in behavior.
>>> These two changes could be included in 1.5 if Ralf feels this is
>>> worthwhile.
>>> That looks like a reasonable solution. I haven't got a strong opinion on
>> whether or not to change the 'normed' keyword to 'density'.
>> Looking at the changes, I don't think that is the right way to do the
>> filtering in the tests. resetwarnings() removes all filters including the
>> ones previously set by users, and should therefore not be used. Better to
>> either raise a specific warning and filter on that, or to filter on the
>> message content with:
>>     warnings.filterwarnings('ignore' , message="This release of NumPy
>> fixes a normalization bug in histogram").
>> I found one more place where resetwarnings() is used, in
>> test_arraysetops.py, I'll change that in trunk. Related problem there is
>> that the warning in warnings.warn is not a DeprecationWarning.
>> The above problem is easy to fix, but in any case it's too late to go into
>> 1.5.0 - I'll tag the final release tonight.
> Ralf,
> test_function_base and test_arraysetops now do not use resetwarnings. What
> I did is added a warning filter and popped it out of the filters list
> afterwards. Is this OK ?

That looks like the best solution to me (besides the catch_warnings context
manager, which we can't use).

> In other tests, what is done is rather
>   warnings.simplefilter('ignore', DeprecationWarning)
>   test_function()
>   warnings.simplefilter('default', DeprecationWarning)
> but that will also override any user-defined setup, no ?

Yes, it's less invasive than resetwarnings() but could also be annoying for
some users. Would be good to do this in a consistent way for all warnings
and tests, and describe that in

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100831/ce47c02e/attachment.html 

More information about the NumPy-Discussion mailing list