Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa19374

Browse filesBrowse files
jklymaktimhoffm
authored andcommitted
Backport PR #12277: FIX: datetime64 now recognized if in a list
1 parent e3909ac commit aa19374
Copy full SHA for aa19374

File tree

Expand file treeCollapse file tree

2 files changed

+13
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-6
lines changed

‎lib/matplotlib/dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dates.py
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,19 @@ def date2num(d):
410410
Gregorian calendar is assumed; this is not universal practice.
411411
For details see the module docstring.
412412
"""
413-
414413
if hasattr(d, "values"):
415414
# this unpacks pandas series or dataframes...
416415
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)
422420
return _to_ordinalf(d)
421+
423422
else:
424423
d = np.asarray(d)
424+
if np.issubdtype(d.dtype, np.datetime64):
425+
return _dt64_to_ordinalf(d)
425426
if not d.size:
426427
return d
427428
return _to_ordinalf_np_vectorized(d)

‎lib/matplotlib/tests/test_dates.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_dates.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,9 @@ def test_tz_utc():
641641
def 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.])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.