diff --git a/doc/api/next_api_changes/2018-01-31-AL.rst b/doc/api/next_api_changes/2018-01-31-AL.rst new file mode 100644 index 000000000000..ace7046efe0c --- /dev/null +++ b/doc/api/next_api_changes/2018-01-31-AL.rst @@ -0,0 +1,8 @@ +Deprecations +```````````` + +``dates.strpdate2num`` and ``dates.bytespdate2num`` are brittle in the +presence of locale changes, and are deprecated. Use standard datetime +parsers such as `time.strptime` or `dateutil.parser.parse`, and additionally +call `matplotlib.dates.date2num` if you insist on converting to Matplotlib's +internal datetime representation; or use ``dates.datestr2num``. diff --git a/examples/misc/load_converter.py b/examples/misc/load_converter.py index 2c3e03f73b89..5f0d7940f1cc 100644 --- a/examples/misc/load_converter.py +++ b/examples/misc/load_converter.py @@ -1,8 +1,10 @@ """ ============== -Load Converter +Load converter ============== +This example demonstrates passing a custom converter to `numpy.genfromtxt` to +extract dates from a CSV file. """ import dateutil.parser @@ -16,9 +18,9 @@ data = np.genfromtxt( datafile, delimiter=',', names=True, - converters={0: lambda s: dates.date2num(dateutil.parser.parse(s))}) + dtype=None, converters={0: dateutil.parser.parse}) fig, ax = plt.subplots() -ax.plot_date(data['Date'], data['High'], '-') +ax.plot(data['Date'], data['High'], '-') fig.autofmt_xdate() plt.show() diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index ed0f9ae1e45b..016656ab3f61 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -317,6 +317,8 @@ def _from_ordinalf(x, tz=None): _from_ordinalf_np_vectorized = np.vectorize(_from_ordinalf) +@cbook.deprecated( + "3.1", alternative="time.strptime or dateutil.parser.parse or datestr2num") class strpdate2num(object): """ Use this class to parse date strings to matplotlib datenums when @@ -333,6 +335,8 @@ def __call__(self, s): return date2num(datetime.datetime(*time.strptime(s, self.fmt)[:6])) +@cbook.deprecated( + "3.1", alternative="time.strptime or dateutil.parser.parse or datestr2num") class bytespdate2num(strpdate2num): """ Use this class to parse date strings to matplotlib datenums when