File tree 2 files changed +12
-5
lines changed
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -405,18 +405,19 @@ def date2num(d):
405
405
Gregorian calendar is assumed; this is not universal practice.
406
406
For details see the module docstring.
407
407
"""
408
-
409
408
if hasattr (d , "values" ):
410
409
# this unpacks pandas series or dataframes...
411
410
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 )
416
411
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 )
417
415
return _to_ordinalf (d )
416
+
418
417
else :
419
418
d = np .asarray (d )
419
+ if np .issubdtype (d .dtype , np .datetime64 ):
420
+ return _dt64_to_ordinalf (d )
420
421
if not d .size :
421
422
return d
422
423
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