@@ -255,6 +255,11 @@ def _dt64_to_ordinalf(d):
255255 because we do times compared to ``0001-01-01T00:00:00`` (plus one day).
256256 """
257257
258+ if (isinstance (d ,np .timedelta64 )or
259+ (isinstance (d ,np .ndarray )and
260+ np .issubdtype (d .dtype ,np .timedelta64 ))):
261+ return d / np .timedelta64 (1 ,'D' )
262+
258263# the "extra" ensures that we at least allow the dynamic range out to
259264# seconds. That should get out to +/-2e11 years.
260265# NOTE: First cast truncates; second cast back is for NumPy 1.10.
@@ -275,6 +280,13 @@ def _dt64_to_ordinalf(d):
275280return dt
276281
277282
283+ def _dt64_to_ordinalf_iterable (d ):
284+ dnew = np .zeros (len (d ))
285+ for nn ,dd in enumerate (d ):
286+ dnew [nn ]= _dt64_to_ordinalf (dd )
287+ return (dnew )
288+
289+
278290def _from_ordinalf (x ,tz = None ):
279291"""
280292 Convert Gregorian float of the date, preserving hours, minutes,
@@ -413,19 +425,31 @@ def date2num(d):
413425if hasattr (d ,"values" ):
414426# this unpacks pandas series or dataframes...
415427d = d .values
416- if not np .iterable (d ):
417- if (isinstance (d ,np .datetime64 )or (isinstance (d ,np .ndarray )and
418- np .issubdtype (d .dtype ,np .datetime64 ))):
419- return _dt64_to_ordinalf (d )
420- return _to_ordinalf (d )
421428
422- else :
423- d = np . asarray ( d )
424- if np .issubdtype ( d . dtype ,np .datetime64 ):
429+ if not np . iterable ( d ) and not isinstance ( d , np . ndarray ) :
430+ # single value logic...
431+ if ( isinstance ( d , np .datetime64 ) or isinstance ( d ,np .timedelta64 ) ):
425432return _dt64_to_ordinalf (d )
426- if not d .size :
427- return d
433+ else :
434+ return _to_ordinalf (d )
435+
436+ elif (isinstance (d ,np .ndarray )and
437+ (np .issubdtype (d .dtype ,np .datetime64 )or
438+ np .issubdtype (d .dtype ,np .timedelta64 ))):
439+ # array with all one type of datetime64 object.
440+ return _dt64_to_ordinalf (d )
441+
442+ elif len (d ):
443+ # this is a list or tuple...
444+ if (isinstance (d [0 ],np .datetime64 )or
445+ isinstance (d [0 ],np .timedelta64 )):
446+ return _dt64_to_ordinalf_iterable (d )
428447return _to_ordinalf_np_vectorized (d )
448+ elif hasattr (d ,'size' )and not d .size :
449+ # this is an empty
450+ return d
451+ else :
452+ return []
429453
430454
431455def julian2num (j ):