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

Skip to content

Commit e7fb714

Browse files
authored
Merge pull request #13319 from anntzer/pdate2num
Deprecate dates.{str,bytes}pdate2num.
2 parents e714048 + ef3e89e commit e7fb714

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Deprecations
2+
````````````
3+
4+
``dates.strpdate2num`` and ``dates.bytespdate2num`` are brittle in the
5+
presence of locale changes, and are deprecated. Use standard datetime
6+
parsers such as `time.strptime` or `dateutil.parser.parse`, and additionally
7+
call `matplotlib.dates.date2num` if you insist on converting to Matplotlib's
8+
internal datetime representation; or use ``dates.datestr2num``.

examples/misc/load_converter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""
22
==============
3-
Load Converter
3+
Load converter
44
==============
55
6+
This example demonstrates passing a custom converter to `numpy.genfromtxt` to
7+
extract dates from a CSV file.
68
"""
79

810
import dateutil.parser
@@ -16,9 +18,9 @@
1618

1719
data = np.genfromtxt(
1820
datafile, delimiter=',', names=True,
19-
converters={0: lambda s: dates.date2num(dateutil.parser.parse(s))})
21+
dtype=None, converters={0: dateutil.parser.parse})
2022

2123
fig, ax = plt.subplots()
22-
ax.plot_date(data['Date'], data['High'], '-')
24+
ax.plot(data['Date'], data['High'], '-')
2325
fig.autofmt_xdate()
2426
plt.show()

lib/matplotlib/dates.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ def _from_ordinalf(x, tz=None):
317317
_from_ordinalf_np_vectorized = np.vectorize(_from_ordinalf)
318318

319319

320+
@cbook.deprecated(
321+
"3.1", alternative="time.strptime or dateutil.parser.parse or datestr2num")
320322
class strpdate2num(object):
321323
"""
322324
Use this class to parse date strings to matplotlib datenums when
@@ -333,6 +335,8 @@ def __call__(self, s):
333335
return date2num(datetime.datetime(*time.strptime(s, self.fmt)[:6]))
334336

335337

338+
@cbook.deprecated(
339+
"3.1", alternative="time.strptime or dateutil.parser.parse or datestr2num")
336340
class bytespdate2num(strpdate2num):
337341
"""
338342
Use this class to parse date strings to matplotlib datenums when

0 commit comments

Comments
 (0)