diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-12-29 22:15:02 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-12-29 22:15:02 +0000 |
commit | 55a0865b70c49a693d406c0a661cc43827c13f1f (patch) | |
tree | e401e6ca753a6d81ec39f90415056c6319ea1693 | |
parent | d54955f3f535bf65eba8b3b7e22ff3d9212b5a82 (diff) | |
download | numpy-55a0865b70c49a693d406c0a661cc43827c13f1f.tar.gz |
Fixed up chararray a bit.
-rw-r--r-- | scipy/base/chararray.py | 33 | ||||
-rw-r--r-- | scipy/base/src/arraytypes.inc.src | 1 | ||||
-rw-r--r-- | scipy/base/src/multiarraymodule.c | 6 |
3 files changed, 22 insertions, 18 deletions
diff --git a/scipy/base/chararray.py b/scipy/base/chararray.py index 7f7573d32..57e06a67e 100644 --- a/scipy/base/chararray.py +++ b/scipy/base/chararray.py @@ -282,25 +282,29 @@ class chararray(ndarray): return self._generalmethod('zfill', broadcast(self, width)) -def array(obj, itemlen=7, copy=True, unicode=False, fortran=False): +def array(obj, itemsize=None, copy=True, unicode=False, fortran=False): if isinstance(obj, chararray): - if copy or (itemlen != obj.itemlen) \ + if itemsize is None: + itemsize = obj.itemsize + if copy or (itemsize != obj.itemsize) \ or (not unicode and obj.dtype == unicode_) \ or (unicode and obj.dtype == string): - return obj.astype("%s%d" % (obj.dtypechar, itemlen)) + return obj.astype("%s%d" % (obj.dtypechar, itemsize)) else: return obj if isinstance(obj, ndarray) and (obj.dtype in [unicode_, string]): + if itemsize is None: + itemsize = obj.itemsize copied = 0 if unicode: - dtype = 'U%d' % obj.itemlen + dtype = 'U%d' % obj.itemsize if obj.dtype == string: obj = obj.astype(dtype) copied = 1 else: - dtype = 'S%d' % obj.itemlen + dtype = 'S%d' % obj.itemsize if obj.dtype == unicode_: obj = obj.astype(dtype) copied = 1 @@ -308,21 +312,22 @@ def array(obj, itemlen=7, copy=True, unicode=False, fortran=False): if copy and not copied: obj = obj.copy() - return ndarray.__new__(chararray, obj.shape, (dtype, itemlen), + return ndarray.__new__(chararray, obj.shape, dtype, buffer=obj, offset=0, fortran=obj.flags['FNC']) - if unicode: - dtype = "U%d" % itemlen - else: - dtype = "S%d" % itemlen + if unicode: dtype = "U" + else: dtype = "S" + + if itemsize is not None: + dtype += str(itemsize) val = narray(obj, dtype=dtype, fortran=fortran, subok=1) - return chararray(val.shape, itemlen, unicode, buffer=val, + return chararray(val.shape, itemsize, unicode, buffer=val, strides=val.strides, fortran=fortran) -def asarray(obj, itemlen=7, unicode=False, fortran=False): - return chararray(obj, itemlen, copy=False, - unicode=unicode, fortran=fortran) +def asarray(obj, itemsize=None, unicode=False, fortran=False): + return array(obj, itemsize, copy=False, + unicode=unicode, fortran=fortran) diff --git a/scipy/base/src/arraytypes.inc.src b/scipy/base/src/arraytypes.inc.src index 0275d56b1..a64552f0c 100644 --- a/scipy/base/src/arraytypes.inc.src +++ b/scipy/base/src/arraytypes.inc.src @@ -377,7 +377,6 @@ static int PyArray_CopyObject(PyArrayObject *, PyObject *); static int VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) { - PyObject *u=NULL; PyArray_Descr* descr; int itemsize=ap->descr->elsize; int res; diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c index 825166e3b..55f68f1db 100644 --- a/scipy/base/src/multiarraymodule.c +++ b/scipy/base/src/multiarraymodule.c @@ -1608,9 +1608,9 @@ PyArray_Sort(PyArrayObject *op, int axis) SWAPAXES(op, ap); - ap = (PyArrayObject *)PyArray_CopyFromObject((PyObject *)op, - PyArray_NOTYPE, - 1, 0); + ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, + NULL, 1, 0, ENSURECOPY); + Py_DECREF(op); if (ap == NULL) return NULL; |