summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-09-16 02:08:59 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-09-16 02:08:59 +0000
commit8b6db6e885dec95dda7bbe2001d95bdee63e6cf1 (patch)
tree66e012c2479c69c935529d6f56488829f2433995
parentf74f1d14f0768650a7dd5327944ddcc82f0d892d (diff)
downloadnumpy-8b6db6e885dec95dda7bbe2001d95bdee63e6cf1.tar.gz
Fix ticket #188 by returning the name of the dtype objects for data-type objects without fields or sub-arrays that are in correct byte-order
-rw-r--r--numpy/core/src/arrayobject.c23
-rw-r--r--numpy/lib/twodim_base.py3
-rw-r--r--numpy/lib/utils.py5
-rw-r--r--numpy/numarray/functions.py64
4 files changed, 70 insertions, 25 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 1a126e3e2..4cfb02a4a 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -11086,6 +11086,12 @@ arraydescr_str(PyArray_Descr *self)
PyObject *p;
PyObject *t = PyString_FromString("(");
p = arraydescr_str(self->subarray->base);
+ if (!self->subarray->base->names && !self->subarray->base->subarray) {
+ PyObject *t=PyString_FromString("'");
+ PyString_Concat(&p, t);
+ PyString_ConcatAndDel(&t, p);
+ p = t;
+ }
PyString_ConcatAndDel(&t, p);
PyString_ConcatAndDel(&t, PyString_FromString(","));
PyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));
@@ -11093,11 +11099,12 @@ arraydescr_str(PyArray_Descr *self)
sub = t;
}
else {
- PyObject *t=PyString_FromString("'");
- sub = arraydescr_protocol_typestr_get(self);
- PyString_Concat(&sub, t);
- PyString_ConcatAndDel(&t, sub);
- sub = t;
+ if (!PyArray_ISNBO(self->byteorder)) {
+ sub = arraydescr_protocol_typestr_get(self);
+ }
+ else {
+ sub = arraydescr_typename_get(self);
+ }
}
return sub;
}
@@ -11108,6 +11115,12 @@ arraydescr_repr(PyArray_Descr *self)
PyObject *sub, *s;
s = PyString_FromString("dtype(");
sub = arraydescr_str(self);
+ if (!self->names && !self->subarray) {
+ PyObject *t=PyString_FromString("'");
+ PyString_Concat(&sub, t);
+ PyString_ConcatAndDel(&t, sub);
+ sub = t;
+ }
PyString_ConcatAndDel(&s, sub);
sub = PyString_FromString(")");
PyString_ConcatAndDel(&s, sub);
diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py
index 512b6bf53..d79fd03c6 100644
--- a/numpy/lib/twodim_base.py
+++ b/numpy/lib/twodim_base.py
@@ -143,7 +143,7 @@ def vander(x, N=None):
X[:,i] = x**(N-i-1)
return X
-def histogram2d(x,y, bins=10, range=None, normed=False):
+def histogram2d(x,y, bins=10, range=None, normed=False):
"""histogram2d(x,y, bins=10, range=None, normed=False) -> H, xedges, yedges
Compute the 2D histogram from samples x,y.
@@ -159,7 +159,6 @@ def histogram2d(x,y, bins=10, range=None, normed=False):
The histogram array is a count of the number of samples in each
two dimensional bin.
Setting normed to True returns a density rather than a bin count.
- Data falling outside of the edges are not counted.
"""
import numpy as np
try:
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index b6ee51b91..981ec6de5 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -238,7 +238,10 @@ def info(object=None,maxwidth=76,output=sys.stdout,toplevel='numpy'):
if object is None:
info(info)
- elif isinstance(object, types.StringType):
+ elif isinstance(object, ndarray):
+ import numpy.numarray as nn
+ nn.info(object, output=output, numpy=1)
+ elif isinstance(object, str):
if _namedict is None:
_namedict, _dictlist = _makenamedict(toplevel)
numfound = 0
diff --git a/numpy/numarray/functions.py b/numpy/numarray/functions.py
index fb1c597ac..3a2939d1e 100644
--- a/numpy/numarray/functions.py
+++ b/numpy/numarray/functions.py
@@ -340,27 +340,57 @@ def identity(n, type=None, typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, True)
return N.identity(n, dtype)
-def info(obj):
- print "class: ", type(obj)
- print "shape: ", obj.shape
- print "strides: ", obj.strides
- print "byteoffset: 0"
- print "bytestride: ", obj.strides[0]
- print "itemsize: ", obj.itemsize
- print "aligned: ", obj.flags.aligned
- print "contiguous: ", obj.flags.contiguous
- print "buffer: ", repr(obj.data)
- print "data pointer:", obj.ctypes._as_parameter_, "(DEBUG ONLY)"
- print "byteorder: ",
+def info(obj, output=sys.stdout, numpy=0):
+ if numpy:
+ bp = lambda x: x
+ else:
+ bp = lambda x: int(x)
+ cls = getattr(obj, '__class__', type(obj))
+ if numpy:
+ nm = getattr(cls, '__name__', cls)
+ else:
+ nm = cls
+ print >> output, "class: ", nm
+ print >> output, "shape: ", obj.shape
+ strides = obj.strides
+ print >> output, "strides: ", strides
+ if not numpy:
+ print >> output, "byteoffset: 0"
+ if len(strides) > 0:
+ bs = obj.strides[0]
+ else:
+ bs = obj.itemsize
+ print >> output, "bytestride: ", bs
+ print >> output, "itemsize: ", obj.itemsize
+ print >> output, "aligned: ", bp(obj.flags.aligned)
+ print >> output, "contiguous: ", bp(obj.flags.contiguous)
+ if numpy:
+ print >> output, "fortran: ", obj.flags.fortran
+ if not numpy:
+ print >> output, "buffer: ", repr(obj.data)
+ if not numpy:
+ extra = " (DEBUG ONLY)"
+ tic = "'"
+ else:
+ extra = ""
+ tic = ""
+ print >> output, "data pointer: %s%s" % (hex(obj.ctypes._as_parameter_), extra)
+ print >> output, "byteorder: ",
endian = obj.dtype.byteorder
if endian in ['|','=']:
- print sys.byteorder
+ print >> output, "%s%s%s" % (tic, sys.byteorder, tic)
+ byteswap = False
elif endian == '>':
- print "big"
+ print >> output, "%sbig%s" % (tic, tic)
+ byteswap = sys.byteorder != "big"
+ else:
+ print >> output, "%slittle%s" % (tic, tic)
+ byteswap = sys.byteorder != "little"
+ print >> output, "byteswap: ", bp(byteswap)
+ if not numpy:
+ print >> output, "type: ", typefrom(obj).name
else:
- print "little"
- print "byteswap: ", not obj.dtype.isnative
- print "type: ", typefrom(obj).name
+ print >> output, "type: %s" % obj.dtype
#clipmode is ignored if axis is not 0 and array is not 1d
def put(array, indices, values, axis=0, clipmode=RAISE):