summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerrit Holl <gerrit.holl@utoronto.ca>2015-01-15 15:32:28 -0500
committerJulian Taylor <jtaylor.debian@googlemail.com>2015-01-25 17:02:17 +0100
commitf7cdfe6425a3366bae488d20cdf0c87b9bca8096 (patch)
tree78477bbd5fd1924d922dcdd633b4ef4cef93d113
parent33bd2055435e647618969f68b850b33a986a6ea3 (diff)
downloadnumpy-f7cdfe6425a3366bae488d20cdf0c87b9bca8096.tar.gz
BUG: Fix #4476 by adding datetime64 and timedelta64 types
This commit fixes bug #4476 by adding the codes for the datetime64 and timedelta64 types to the `default_filler` dictionary in numpy.ma.core, used by `default_fill_value`. Also adapt checking in the `default_fill_value` to include code for timedelta64, not only datetime64.
-rw-r--r--numpy/ma/core.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 34e52d86e..9e4fb9685 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -145,10 +145,15 @@ default_filler = {'b': True,
'S' : 'N/A',
'u' : 999999,
'V' : '???',
- 'U' : 'N/A',
- 'M8[D]' : np.datetime64('NaT', 'D'),
- 'M8[us]' : np.datetime64('NaT', 'us')
+ 'U' : 'N/A'
}
+
+# Add datetime64 and timedelta64 types
+for v in ["Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns", "ps",
+ "fs", "as"]:
+ default_filler["M8[" + v + "]"] = np.datetime64("NaT", v)
+ default_filler["m8[" + v + "]"] = np.timedelta64("NaT", v)
+
max_filler = ntypes._minvals
max_filler.update([(k, -np.inf) for k in [np.float32, np.float64]])
min_filler = ntypes._maxvals
@@ -194,7 +199,7 @@ def default_fill_value(obj):
999999
>>> np.ma.default_fill_value(np.array([1.1, 2., np.pi]))
1e+20
- >>> np.ma.default_fill_value(np.dtype(complex))
+ >>> np.ma.default_fill_value(np.dtype(complex))
(1e+20+0j)
"""
@@ -203,7 +208,7 @@ def default_fill_value(obj):
elif isinstance(obj, np.dtype):
if obj.subdtype:
defval = default_filler.get(obj.subdtype[0].kind, '?')
- elif obj.kind == 'M':
+ elif obj.kind in 'Mm':
defval = default_filler.get(obj.str[1:], '?')
else:
defval = default_filler.get(obj.kind, '?')