File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -410,18 +410,19 @@ def date2num(d):
410
410
Gregorian calendar is assumed; this is not universal practice.
411
411
For details see the module docstring.
412
412
"""
413
-
414
413
if hasattr (d , "values" ):
415
414
# this unpacks pandas series or dataframes...
416
415
d = d .values
417
-
418
- if ((isinstance (d , np .ndarray ) and np .issubdtype (d .dtype , np .datetime64 ))
419
- or isinstance (d , np .datetime64 )):
420
- return _dt64_to_ordinalf (d )
421
- if not cbook .iterable (d ):
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 )
422
420
return _to_ordinalf (d )
421
+
423
422
else :
424
423
d = np .asarray (d )
424
+ if np .issubdtype (d .dtype , np .datetime64 ):
425
+ return _dt64_to_ordinalf (d )
425
426
if not d .size :
426
427
return d
427
428
return _to_ordinalf_np_vectorized (d )
Original file line number Diff line number Diff line change @@ -641,3 +641,9 @@ def test_tz_utc():
641
641
def test_num2timedelta (x , tdelta ):
642
642
dt = mdates .num2timedelta (x )
643
643
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