File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -497,7 +497,7 @@ def array_to_timedelta64(
497497 errors = errors,
498498 creso = state.creso,
499499 )
500- elif state. creso == NPY_DATETIMEUNIT.NPY_FR_GENERIC:
500+ elif creso == NPY_DATETIMEUNIT.NPY_FR_GENERIC:
501501 # i.e. we never encountered anything non-NaT, default to "s". This
502502 # ensures that insert and concat-like operations with NaT
503503 # do not upcast units
@@ -507,9 +507,10 @@ def array_to_timedelta64(
507507 # a second pass.
508508 abbrev = npy_unit_to_abbrev(state.creso)
509509 result = iresult.view(f" m8[{abbrev}]" )
510-
511- abbrev = npy_unit_to_abbrev(creso)
512- return result.view(f" m8[{abbrev}]" )
510+ else :
511+ abbrev = npy_unit_to_abbrev(creso)
512+ result = result.view(f" m8[{abbrev}]" )
513+ return result
513514
514515
515516@ cython.cpow (True )
Original file line number Diff line number Diff line change 2727
2828
2929class TestTimedeltas :
30+ def test_to_timedelta_all_nat_unit (self ):
31+ # With all-NaT entries, we get "s" unit
32+ result = to_timedelta ([None ])
33+ assert result .unit == "s"
34+
35+ result = TimedeltaIndex ([None ])
36+ assert result .unit == "s"
37+
3038 def test_to_timedelta_month_raises (self ):
3139 obj = np .timedelta64 (1 , "M" )
3240
You can’t perform that action at this time.
0 commit comments