[Numpy-tickets] [NumPy] #351: set_string_function(None) for reset of array_repr
NumPy
numpy-tickets at scipy.net
Tue Oct 17 16:56:11 CDT 2006
#351: set_string_function(None) for reset of array_repr
-------------------------+--------------------------------------------------
Reporter: mackeith | Owner: somebody
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: numpy.core | Version:
Severity: normal | Keywords:
-------------------------+--------------------------------------------------
Currently it is not possible to reset the repr and str methods of the
numpy array to use the built in functions array_repr and array_str. These
are set in numeric.py to use Python functions, and cannot be reset to the
built-in c functions.
I propose that
'set_string_function(None, 0/1)'
will reset the str/repr function to the built-in version.
The changes to arrayobject.c and multiarraymodule.c are below:
{{{
--- arrayobject.c Tue Oct 17 17:53:35 2006
***************
*** 4132,4148 ****
if (repr) {
/* Dispose of previous callback */
Py_XDECREF(PyArray_ReprFunction);
! /* Add a reference to new callback */
! Py_XINCREF(op);
! /* Remember new callback */
! PyArray_ReprFunction = op;
} else {
/* Dispose of previous callback */
Py_XDECREF(PyArray_StrFunction);
! /* Add a reference to new callback */
! Py_XINCREF(op);
! /* Remember new callback */
! PyArray_StrFunction = op;
}
}
--- 4132,4162 ----
if (repr) {
/* Dispose of previous callback */
Py_XDECREF(PyArray_ReprFunction);
! if (op == Py_None)
! {
! PyArray_ReprFunction = NULL;
! }
! else
! {
! /* Add a reference to new callback */
! Py_XINCREF(op);
! /* Remember new callback */
! PyArray_ReprFunction = op;
! }
} else {
/* Dispose of previous callback */
Py_XDECREF(PyArray_StrFunction);
! if (op == Py_None)
! {
! PyArray_StrFunction = NULL;
! }
! else
! {
! /* Add a reference to new callback */
! Py_XINCREF(op);
! /* Remember new callback */
! PyArray_StrFunction = op;
! }
}
}
}}}
{{{
--- multiarraymodule.c Tue Oct 17 14:08:51 2006
***************
*** 6376,6382 ****
if(!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist,
&op, &repr)) return NULL;
! if (!PyCallable_Check(op)) {
PyErr_SetString(PyExc_TypeError,
"Argument must be callable.");
return NULL;
--- 6376,6382 ----
if(!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist,
&op, &repr)) return NULL;
! if (!PyCallable_Check(op) && op != Py_None) {
PyErr_SetString(PyExc_TypeError,
"Argument must be callable or None.");
return NULL;}}}
--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/351>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list