[Numpy-discussion] Issues to fix for 1.7.0rc2.

Charles R Harris charlesr.harris@gmail....
Wed Feb 6 00:46:05 CST 2013


On Tue, Feb 5, 2013 at 11:14 PM, Charles R Harris <charlesr.harris@gmail.com
> wrote:

>
>
> On Tue, Feb 5, 2013 at 10:23 PM, Jason Grout <jason-sage@creativetrax.com>wrote:
>
>> On 2/4/13 12:04 AM, Ondřej Čertík wrote:
>> > Hi,
>> >
>> > Here are the last open issues for 1.7, there are 9 of them:
>> >
>> >
>> https://github.com/numpy/numpy/issues?milestone=3&sort=updated&state=open
>> >
>>
>> Here's something we noticed while working on getting 1.7rc1 into Sage
>> with one of our doctests.  With numpy 1.5.1 (we skipped 1.6.x because of
>> backwards compatibility issues...):
>>
>> import numpy as np
>> print np.array([None, None]).any()
>>
>> prints False, but with 1.7.rc1, we get None.
>>
>> For comparison, in Python 2.6.1 and 3.3.0:
>>
>>  >>> any([None,None])
>> False
>>  >>> print None or None
>> None
>>
>> Was this change between 1.5.1 and 1.7 intentional?
>>
>>
> Probably not, but maybe yes. I'd guess the cause is lines 2601-2603 of
> ufunc_object.c
>
>             if (PyArray_ISOBJECT(arr) && PyArray_SIZE(arr) != 0) {
>                 assign_identity = NULL;
>             }
>
>
> The variable assign_identity is a function pointer, so some new functions
> are probably needed that return python integers 0 and 1 when PyUFunc_Zero
> and PyUFunc_One turn up. I don't know what all the consequences of that
> change would be and it may not be quite so simple. Clearly that code isn't
> well tested.
>
>
Oh, and you do realize Python is insane here. None really shouldn't *have*
a logical value, which I suppos

>>> 0 or None
>>> 1 or None
1
>>> print None or None
None

If ndarray.any is equivalent to logical_or.reduce there is no way to make
all those work. We will need to special case some things. In fact, in 1.5
logical_or was not defined for object dtypes, so any must have been special
cased and the change that has come about is from implementing logical_or
for objects and using a reduction. So in 1.5

>>> a = np.array([None, None], dtype='O')
>>> np.logical_or(a,a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: logical_or
>>> a = np.array([1, 1])
>>> np.logical_or(a,a)
array([ True,  True], dtype=bool)

While in 1.7

In [1]: a = array([None, None])

In [2]: logical_or(a, a)
Out[2]: array([None, None], dtype=object)

In [3]: logical_or(a, 0)
Out[3]: array([0, 0], dtype=object)

In [4]: logical_or(a, 1)
Out[4]: array([1, 1], dtype=object)

Which agrees with python in two out of three. Not bad for dealing with
insane inconsistency. And it looks like the changes suggested in the
previous post will fix the problem if we decide to do so.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130205/197ad97b/attachment-0001.html 


More information about the NumPy-Discussion mailing list