8000 BUG: Fix #4476 by adding datetime64 and timedelta64 types · juliantaylor/numpy@f7cdfe6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f7cdfe6

Browse files
Gerrit Holljuliantaylor
authored andcommitted
BUG: Fix numpy#4476 by adding datetime64 and timedelta64 types
This commit fixes bug numpy#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.
1 parent 33bd205 commit f7cdfe6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

numpy/ma/core.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,15 @@ class MaskError(MAError):
145145
'S' : 'N/A',
146146
'u' : 999999,
147147
'V' : '???',
148-
'U' : 'N/A',
149-
'M8[D]' : np.datetime64('NaT', 'D'),
150-
'M8[us]' : np.datetime64('NaT', 'us')
148+
'U' : 'N/A'
151149
}
150+
151+
# Add datetime64 and timedelta64 types
152+
for v in ["Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns", "ps",
153+
"fs", "as"]:
154+
default_filler["M8[" + v + "]"] = np.datetime64("NaT", v)
155+
default_filler["m8[" + v + "]"] = np.timedelta64("NaT", v)
156+
152157
max_filler = ntypes._minvals
153158
max_filler.update([(k, -np.inf) for k in [np.float32, np.float64]])
154159
min_filler = ntypes._maxvals
@@ -194,7 +199,7 @@ def default_fill_value(obj):
194199
999999
195200
>>> np.ma.default_fill_value(np.array([1.1, 2., np.pi]))
196201
1e+20
197-
>>> np.ma.default_fill_value(np.dtype(complex))
202+
>>> np.ma.default_fill_value(np.dtype(complex))
198203
(1e+20+0j)
199204
200205
"""
@@ -203,7 +208,7 @@ def default_fill_value(obj):
203208
elif isinstance(obj, np.dtype):
204209
if obj.subdtype:
205210
defval = default_filler.get(obj.subdtype[0].kind, '?')
206-
elif obj.kind == 'M':
211+
elif obj.kind in 'Mm':
207212
defval = default_filler.get(obj.str[1:], '?')
208213
else:
209214
defval = default_filler.get(obj.kind, '?')

0 commit comments

Comments
 (0)
0