summaryrefslogtreecommitdiff
path: root/numpy/ma/core.py
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2009-01-04 20:16:00 +0000
committerpierregm <pierregm@localhost>2009-01-04 20:16:00 +0000
commit0d76f639e0bac272f0feeeb681453af7539e7d1b (patch)
tree961033069a1e8d8ae7370146f701b80c99dc1708 /numpy/ma/core.py
parent6458485c880802fb1cc831cac2d22db5b0004438 (diff)
downloadnumpy-0d76f639e0bac272f0feeeb681453af7539e7d1b.tar.gz
* adapted default_fill_value for flexible datatype
* fixed max/minimum_fill_value for flexible datatype
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r--numpy/ma/core.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 3ea5a3da5..24ee79693 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -152,7 +152,7 @@ def default_fill_value(obj):
"""
if hasattr(obj,'dtype'):
- defval = default_filler[obj.dtype.kind]
+ defval = _check_fill_value(None, obj.dtype)
elif isinstance(obj, np.dtype):
if obj.subdtype:
defval = default_filler[obj.subdtype[0].kind]
@@ -170,6 +170,18 @@ def default_fill_value(obj):
defval = default_filler['O']
return defval
+
+def _recursive_extremum_fill_value(ndtype, extremum):
+ names = ndtype.names
+ if names:
+ deflist = []
+ for name in names:
+ fval = _recursive_extremum_fill_value(ndtype[name], extremum)
+ deflist.append(fval)
+ return tuple(deflist)
+ return extremum[ndtype]
+
+
def minimum_fill_value(obj):
"""
Calculate the default fill value suitable for taking the minimum of ``obj``.
@@ -177,11 +189,7 @@ def minimum_fill_value(obj):
"""
errmsg = "Unsuitable type for calculating minimum."
if hasattr(obj, 'dtype'):
- objtype = obj.dtype
- filler = min_filler[objtype]
- if filler is None:
- raise TypeError(errmsg)
- return filler
+ return _recursive_extremum_fill_value(obj.dtype, min_filler)
elif isinstance(obj, float):
return min_filler[ntypes.typeDict['float_']]
elif isinstance(obj, int):
@@ -193,6 +201,7 @@ def minimum_fill_value(obj):
else:
raise TypeError(errmsg)
+
def maximum_fill_value(obj):
"""
Calculate the default fill value suitable for taking the maximum of ``obj``.
@@ -200,11 +209,7 @@ def maximum_fill_value(obj):
"""
errmsg = "Unsuitable type for calculating maximum."
if hasattr(obj, 'dtype'):
- objtype = obj.dtype
- filler = max_filler[objtype]
- if filler is None:
- raise TypeError(errmsg)
- return filler
+ return _recursive_extremum_fill_value(obj.dtype, max_filler)
elif isinstance(obj, float):
return max_filler[ntypes.typeDict['float_']]
elif isinstance(obj, int):
@@ -257,7 +262,7 @@ def _check_fill_value(fill_value, ndtype):
if fields:
descr = ndtype.descr
fill_value = np.array(_recursive_set_default_fill_value(descr),
- dtype=ndtype)
+ dtype=ndtype,)
else:
fill_value = default_fill_value(ndtype)
elif fields: