File tree 3 files changed +17
-10
lines changed
3 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -367,16 +367,24 @@ def maybe_promote(dtype, fill_value=np.nan):
367
367
except (TypeError , ValueError ):
368
368
dtype = np .dtype (np .object_ )
369
369
elif issubclass (dtype .type , np .timedelta64 ):
370
- try :
371
- fv = tslibs .Timedelta (fill_value )
372
- except ValueError :
370
+ if (
371
+ is_integer (fill_value )
372
+ or (is_float (fill_value ) and not np .isnan (fill_value ))
373
+ or isinstance (fill_value , str )
374
+ ):
375
+ # TODO: What about str that can be a timedelta?
373
376
dtype = np .dtype (np .object_ )
374
377
else :
375
- if fv is NaT :
376
- # NaT has no `to_timedelta64` method
377
- fill_value = np .timedelta64 ("NaT" , "ns" )
378
+ try :
379
+ fv = tslibs .Timedelta (fill_value )
380
+ except ValueError :
381
+ dtype = np .dtype (np .object_ )
378
382
else :
379
- fill_value = fv .to_timedelta64 ()
383
+ if fv is NaT :
384
+ # NaT has no `to_timedelta64` method
385
+ fill_value = np .timedelta64 ("NaT" , "ns" )
386
+ else :
387
+ fill_value = fv .to_timedelta64 ()
380
388
elif is_datetime64tz_dtype (dtype ):
381
389
if isna (fill_value ):
382
390
fill_value = NaT
Original file line number Diff line number Diff line change @@ -338,6 +338,7 @@ def get_empty_dtype_and_na(join_units):
338
338
if not upcast_classes :
339
339
upcast_classes = null_upcast_classes
340
340
341
+ # TODO: de-duplicate with maybe_promote?
341
342
# create the result
342
343
if "object" in upcast_classes :
343
344
return np .dtype (np .object_ ), np .nan
@@ -356,7 +357,7 @@ def get_empty_dtype_and_na(join_units):
356
357
elif "datetime" in upcast_classes :
357
358
return np .dtype ("M8[ns]" ), tslibs .iNaT
358
359
elif "timedelta" in upcast_classes :
359
- return np .dtype ("m8[ns]" ), tslibs . iNaT
360
+ return np .dtype ("m8[ns]" ), np . timedelta64 ( "NaT" , "ns" )
360
361
else : # pragma
361
362
try :
362
363
g = np .find_common_type (upcast_classes , [])
Original file line number Diff line number Diff line change @@ -821,8 +821,6 @@ def test_maybe_promote_timedelta64_with_any(
821
821
else :
822
822
if boxed and box_dtype is None :
823
823
pytest .xfail ("does not upcast to object" )
824
- if not boxed :
825
- pytest .xfail ("does not upcast to object or raises" )
826
824
827
825
# create array of given dtype; casts "1" to correct dtype
828
826
fill_value = np .array ([1 ], dtype = fill_dtype )[0 ]
You can’t perform that action at this time.
0 commit comments