[Numpy-tickets] [NumPy] #840: SystemError in ndarray.resize, order= argument doesn't work

NumPy numpy-tickets@scipy....
Tue Jan 13 05:28:05 CST 2009


#840: SystemError in ndarray.resize, order= argument doesn't work
--------------------+-------------------------------------------------------
 Reporter:  pv      |        Owner:  somebody
     Type:  defect  |       Status:  new     
 Priority:  normal  |    Milestone:  1.3.0   
Component:  Other   |      Version:  none    
 Severity:  normal  |   Resolution:          
 Keywords:          |  
--------------------+-------------------------------------------------------
Comment (by ScottSinclair):

 I think the problem is related to the following code snippet in the
 array_resize
 function of numpy/core/src/arraymethods.c:

 {{{
 #!C
         ref = PyDict_GetItemString(kwds, "order");
         if (ref != NULL ||
             (PyArray_OrderConverter(ref, &fortran) == PY_FAIL))
             return NULL;
 }}}

 If the 'order' kwarg is specified, then ref != NULL is True and the
 PyArray_OrderConverter function is never called. So I don't see what the
 if statement is supposed to achieve. Perhaps it's meant to be as in
 patch00. This allows 'order' to be silently specified as anything
 without causing an error or having any effect on the result.

 The actual work of resizing is done by calling PyArray_Resize, which
 (according to the Numpy Ref Guide) takes an NPY_ORDER
 argument that has no effect, but is included for future improvements.

 Some options going forward:

 1. Don't document the order keyword.

 2. Apply patch00, issue a warning if the order argument is specified, and
 document that 'order' has no effect.

 3. Remove the order argument from ndarray.resize since it doesn't work and
 raise
 a TypeError if kwargs other than 'refcheck' are specified (patch01 is an
 attempt
 to do this). The current SystemError is not very helpful to users. This
 patch
 causes an error in the test-suite though.

 {{{
 #!python
 Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
 [GCC 4.3.2] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy as np
 >>> np.test()
 Running unit tests for numpy
 NumPy version 1.3.0.dev6319
 NumPy is installed in /home/scott/.virtualenvs/scipy-dev/lib/python2.5
 /site-packages/numpy
 Python version 2.5.2 (r252:60911, Oct  5 2008, 19:24:49) [GCC 4.3.2]
 nose version 0.10.3
 < snip...>

 ======================================================================
 ERROR: test_check_reference (test_multiarray.TestResize)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/home/scott/.virtualenvs/scipy-dev/lib/python2.5/site-
 packages/numpy/core/tests/test_multiarray.py", line 879, in
 test_check_reference
     self.failUnlessRaises(ValueError,x.resize,(5,1))
   File "/usr/lib/python2.5/unittest.py", line 320, in failUnlessRaises
     callableObj(*args, **kwargs)
 TypeError: invalid keyword argument

 ----------------------------------------------------------------------
 Ran 1798 tests in 12.775s

 FAILED (KNOWNFAIL=9, errors=1)
 <nose.result.TextTestResult run=1798 errors=1 failures=0>
 }}}

 Even though the following works as expected

 {{{
 #!python
 >>> x = np.eye(3)
 >>> y = x
 >>> x.resize((5, 1))
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 ValueError: cannot resize an array that has been referenced or is
 referencing
 another array in this way.  Use the resize function
 }}}

 The test failure could be fixed by raising a ValueError instead of a
 TypeError
 in patch01, but that just masks the problem.


 4. Make this work as intended...

-- 
Ticket URL: <http://scipy.org/scipy/numpy/ticket/840#comment:2>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list