diff options
-rw-r--r-- | numpy/core/src/arrayobject.c | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 17 | ||||
-rw-r--r-- | numpy/lib/io.py | 4 |
4 files changed, 24 insertions, 7 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 867b32b65..51abf8e02 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -1976,7 +1976,7 @@ PyArray_ToList(PyArrayObject *self) v=(PyArrayObject *)array_big_item(self, i); } else { - v = PySequence_GetItem((PyObject *)self, i); + v = (PyArrayObject *)PySequence_GetItem((PyObject *)self, i); if ((!PyArray_Check(v)) || (v->nd >= self->nd)) { PyErr_SetString(PyExc_RuntimeError, "array_item not returning smaller-" \ diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index d08b3fd76..9e1fcbe9e 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -849,7 +849,7 @@ __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, if ((new = _check_axis(self, &axis, 0))==NULL) return NULL; /* Compute and reshape mean */ - obj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype, NULL)); + obj1 = PyArray_EnsureAnyArray(PyArray_Mean((PyAO *)new, axis, rtype, NULL)); if (obj1 == NULL) {Py_DECREF(new); return NULL;} n = PyArray_NDIM(new); newshape = PyTuple_New(n); @@ -865,7 +865,7 @@ __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, if (obj2 == NULL) {Py_DECREF(new); return NULL;} /* Compute x = x - mx */ - obj1 = PyArray_EnsureArray(PyNumber_Subtract((PyObject *)new, obj2)); + obj1 = PyArray_EnsureAnyArray(PyNumber_Subtract((PyObject *)new, obj2)); Py_DECREF(obj2); if (obj1 == NULL) {Py_DECREF(new); return NULL;} @@ -878,7 +878,7 @@ __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, Py_INCREF(obj1); } if (obj3 == NULL) {Py_DECREF(new); return NULL;} - obj2 = PyArray_EnsureArray \ + obj2 = PyArray_EnsureAnyArray \ (PyArray_GenericBinaryFunction((PyAO *)obj1, obj3, n_ops.multiply)); Py_DECREF(obj1); Py_DECREF(obj3); @@ -921,7 +921,7 @@ __New_PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, Py_DECREF(obj2); if (!variance) { - obj1 = PyArray_EnsureArray(ret); + obj1 = PyArray_EnsureAnyArray(ret); /* sqrt() */ ret = PyArray_GenericUnaryFunction((PyAO *)obj1, n_ops.sqrt); diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index ae6c43f10..166c3269b 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -854,6 +854,23 @@ class TestView(NumpyTestCase): assert(isinstance(y,np.matrix)) assert_equal(y.dtype,np.int16) +class TestStats(NumpyTestCase): + def test_subclass(self): + class TestArray(np.ndarray): + def __new__(cls, data, info): + result = np.array(data) + result = result.view(cls) + result.info = info + return result + def __array_finalize__(self, obj): + self.info = getattr(obj, "info", '') + dat = TestArray([[1,2,3,4],[5,6,7,8]], 'jubba') + res = dat.mean(1) + assert res.info == dat.info + res = dat.std(1) + assert res.info == dat.info + res = dat.var(1) + assert res.info == dat.info # Import tests without matching module names set_local_path() diff --git a/numpy/lib/io.py b/numpy/lib/io.py index c15e40bba..709a2445a 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -428,7 +428,7 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): import re def fromregex(file, regexp, dtype): - """Construct a record array from a text file, using regular-expressions parsing. + """Construct an array from a text file, using regular-expressions parsing. Array is constructed from all matches of the regular expression in the file. Groups in the regular expression are converted to fields. @@ -440,7 +440,7 @@ def fromregex(file, regexp, dtype): regexp : str or regexp Regular expression to use to parse the file dtype : dtype or dtype list - Dtype for the record array + Dtype for the structured array Example ------- |