Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cac742e

Browse files
committed
Merge pull request matplotlib#2481 from mdboom/datestr2num-fix
datestr2num of year and month fails on 29th, 30th, and 31st of month
2 parents 19b3598 + 66ec634 commit cac742e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/matplotlib/dates.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,24 @@ def __call__(self, s):
246246
return date2num(datetime.datetime(*time.strptime(s, self.fmt)[:6]))
247247

248248

249-
def datestr2num(d):
249+
def datestr2num(d, default=None):
250250
"""
251251
Convert a date string to a datenum using
252-
:func:`dateutil.parser.parse`. *d* can be a single string or a
253-
sequence of strings.
252+
:func:`dateutil.parser.parse`.
253+
254+
Parameters
255+
----------
256+
d : string or sequence of strings
257+
The dates to convert.
258+
259+
default : datetime instance
260+
The default date to use when fields are missing in `d`.
254261
"""
255262
if cbook.is_string_like(d):
256-
dt = dateutil.parser.parse(d)
263+
dt = dateutil.parser.parse(d, default=default)
257264
return date2num(dt)
258265
else:
259-
return date2num([dateutil.parser.parse(s) for s in d])
266+
return date2num([dateutil.parser.parse(s, default=default) for s in d])
260267

261268

262269
def date2num(d):

0 commit comments

Comments
 (0)