File tree 1 file changed +13
-20
lines changed
1 file changed +13
-20
lines changed Original file line number Diff line number Diff line change @@ -264,29 +264,22 @@ def maybe_promote(dtype, fill_value=np.nan):
264
264
265
265
# returns tuple of (dtype, fill_value)
266
266
if issubclass (dtype .type , (np .datetime64 , np .timedelta64 )):
267
- # for now: refuse to upcast datetime64
268
- # (this is because datetime64 will not implicitly upconvert
269
- # to object correctly as of numpy 1.6.1)
270
- # TODO: remove old numpy compat code (without introducing segfault for
271
- # tests/test_take.py::TestTake::test_2d_datetime64)
272
267
if isna (fill_value ):
273
268
fill_value = iNaT
269
+ elif issubclass (dtype .type , np .datetime64 ):
270
+ try :
271
+ fill_value = tslibs .Timestamp (fill_value ).value
272
+ except Exception :
273
+ dtype = np .object_
274
+ fill_value = np .nan
275
+ elif issubclass (dtype .type , np .timedelta64 ):
276
+ try :
277
+ fill_value = tslibs .Timedelta (fill_value ).value
278
+ except Exception :
279
+ dtype = np .object_
280
+ fill_value = np .nan
274
281
else :
275
- if issubclass (dtype .type , np .datetime64 ):
276
- try :
277
- fill_value = tslibs .Timestamp (fill_value ).value
278
- except Exception :
279
- # the proper thing to do here would probably be to upcast
280
- # to object (but numpy 1.6.1 doesn't do this properly)
281
- fill_value = iNaT
282
- elif issubclass (dtype .type , np .timedelta64 ):
283
- try :
284
- fill_value = tslibs .Timedelta (fill_value ).value
285
- except Exception :
286
- # as for datetimes, cannot upcast to object
287
- fill_value = iNaT
288
- else :
289
- fill_value = iNaT
282
+ fill_value = iNaT
290
283
elif is_datetimetz (dtype ):
291
284
if isna (fill_value ):
292
285
fill_value = iNaT
You can’t perform that action at this time.
0 commit comments