Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cc85fb6 commit 2353884Copy full SHA for 2353884
2 files changed
lib/matplotlib/dates.py
@@ -444,7 +444,10 @@ def date2num(d):
444
if not iterable:
445
d = [d]
446
447
+ masked = np.ma.is_masked(d)
448
+ mask = np.ma.getmask(d)
449
d = np.asarray(d)
450
+
451
# convert to datetime64 arrays, if not already:
452
if not np.issubdtype(d.dtype, np.datetime64):
453
# datetime arrays
@@ -458,6 +461,7 @@ def date2num(d):
458
461
459
462
d = d.astype('datetime64[us]')
460
463
464
+ d = np.ma.masked_array(d, mask=mask) if masked else d
465
d = _dt64_to_ordinalf(d)
466
467
return d if iterable else d[0]
lib/matplotlib/tests/test_dates.py
@@ -69,6 +69,26 @@ def test_date2num_NaT_scalar(units):
69
assert np.isnan(tmpl)
70
71
72
+def test_date2num_masked():
73
+ # Without tzinfo
74
+ base = datetime.datetime(2022, 12, 15)
75
+ dates = np.ma.array([base + datetime.timedelta(days=(2 * i))
76
+ for i in range(7)], mask=[0, 1, 1, 0, 0, 0, 1])
77
+ npdates = mdates.date2num(dates)
78
+ np.testing.assert_array_equal(np.ma.getmask(npdates),
79
+ (False, True, True, False, False, False,
80
+ True))
81
82
+ # With tzinfo
83
+ base = datetime.datetime(2022, 12, 15, tzinfo=mdates.UTC)
84
85
86
87
88
89
90
91
92
def test_date_empty():
93
# make sure we do the right thing when told to plot dates even
94
# if no date data has been presented, cf
0 commit comments