File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -405,18 +405,19 @@ def date2num(d):
405405 Gregorian calendar is assumed; this is not universal practice.
406406 For details see the module docstring.
407407 """
408-
409408 if hasattr (d , "values" ):
410409 # this unpacks pandas series or dataframes...
411410 d = d .values
412-
413- if ((isinstance (d , np .ndarray ) and np .issubdtype (d .dtype , np .datetime64 ))
414- or isinstance (d , np .datetime64 )):
415- return _dt64_to_ordinalf (d )
416411 if not np .iterable (d ):
412+ if (isinstance (d , np .datetime64 ) or (isinstance (d , np .ndarray ) and
413+ np .issubdtype (d .dtype , np .datetime64 ))):
414+ return _dt64_to_ordinalf (d )
417415 return _to_ordinalf (d )
416+
418417 else :
419418 d = np .asarray (d )
419+ if np .issubdtype (d .dtype , np .datetime64 ):
420+ return _dt64_to_ordinalf (d )
420421 if not d .size :
421422 return d
422423 return _to_ordinalf_np_vectorized (d )
Original file line number Diff line number Diff line change @@ -641,3 +641,9 @@ def test_tz_utc():
641641def test_num2timedelta (x , tdelta ):
642642 dt = mdates .num2timedelta (x )
643643 assert dt == tdelta
644+
645+
646+ def test_datetime64_in_list ():
647+ dt = [np .datetime64 ('2000-01-01' ), np .datetime64 ('2001-01-01' )]
648+ dn = mdates .date2num (dt )
649+ assert np .array_equal (dn , [730120. , 730486. ])
You can’t perform that action at this time.
0 commit comments