diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-13 10:06:48 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-13 10:06:48 +0000 |
commit | 7168ea12f749508630f83cfc5e39f0a6caf13d84 (patch) | |
tree | a1d035ecab02e032c373130d1f143dfd0d83b357 /numpy/lib/utils.py | |
parent | 3fa71a7122f1a9379b31a35a9f3da9b4f902299b (diff) | |
download | numpy-7168ea12f749508630f83cfc5e39f0a6caf13d84.tar.gz |
Allow for type-less ndpointer.
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index c0701c216..a6330a48f 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -93,7 +93,7 @@ class _ndptr(object): def from_param(cls, obj): if not isinstance(obj, ndarray): raise TypeError("argument must be an ndarray") - if obj.dtype != cls._dtype_: + if cls._dtype_ and obj.dtype != cls._dtype_: raise TypeError("array must have data type", cls._dtype_) if cls._ndim_ and obj.ndim != cls._ndim_: raise TypeError("array must have %d dimension(s)" % cls._ndim_) @@ -107,8 +107,9 @@ class _ndptr(object): # Factory for an array-checking object with from_param defined _pointer_type_cache = {} -def ndpointer(datatype, ndim=None, shape=None, flags=None): - datatype = dtype(datatype) +def ndpointer(datatype=None, ndim=None, shape=None, flags=None): + if datatype is not None: + datatype = dtype(datatype) num = None if flags is not None: if isinstance(flags, str): @@ -122,8 +123,10 @@ def ndpointer(datatype, ndim=None, shape=None, flags=None): try: return _pointer_type_cache[(datatype, ndim, shape, num)] except KeyError: - pass - if datatype.names: + pass + if datatype is None: + name = 'any' + elif datatype.names: name = str(id(datatype)) else: name = datatype.str |