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

Skip to content

Commit 91bc843

Browse files
authored
Merge pull request #10826 from anntzer/py3dates
Py3fy dates.py.
2 parents 3b915df + f98ffad commit 91bc843

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

doc/api/next_api_changes/2018-02-15-AL-deprecations.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ The following modules are deprecated:
99
The following classes, methods, functions, and attributes are deprecated:
1010

1111
- ``Annotation.arrow``,
12-
- ``cbook.GetRealpathAndStat`` (which is only a helper for
13-
``get_realpath_and_stat``),
14-
- ``cbook.Locked``,
12+
- ``cbook.GetRealpathAndStat``, ``cbook.Locked``,
1513
- ``cbook.is_numlike`` (use ``isinstance(..., numbers.Number)`` instead),
14+
``cbook.unicode_safe``
1615
- ``container.Container.set_remove_method``,
16+
- ``dates.DateFormatter.strftime_pre_1900``, ``dates.DateFormatter.strftime``,
1717
- ``font_manager.TempCache``,
1818
- ``mathtext.unichr_safe`` (use ``chr`` instead),
1919
- ``texmanager.dvipng_hack_alpha``,

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from .deprecation import mplDeprecation, MatplotlibDeprecationWarning
3939

4040

41+
@deprecated("3.0")
4142
def unicode_safe(s):
4243

4344
if isinstance(s, bytes):

lib/matplotlib/dates.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,22 @@
135135
* :class:`IndexDateFormatter`: date plots with implicit *x*
136136
indexing.
137137
"""
138-
from __future__ import (absolute_import, division, print_function,
139-
unicode_literals)
140138

141-
import six
142-
from six.moves import zip
143-
import re
144-
import time
145-
import math
146139
import datetime
147140
import functools
148-
149-
import warnings
150141
import logging
142+
import math
143+
import re
144+
import time
145+
import warnings
151146

152147
from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
153148
MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY,
154149
SECONDLY)
155150
from dateutil.relativedelta import relativedelta
156151
import dateutil.parser
157-
import logging
158152
import numpy as np
159153

160-
161154
import matplotlib
162155
from matplotlib import rcParams
163156
import matplotlib.units as units
@@ -404,7 +397,7 @@ def datestr2num(d, default=None):
404397
default : datetime instance, optional
405398
The default date to use when fields are missing in *d*.
406399
"""
407-
if isinstance(d, six.string_types):
400+
if isinstance(d, str):
408401
dt = dateutil.parser.parse(d, default=default)
409402
return date2num(dt)
410403
else:
@@ -629,15 +622,15 @@ def __init__(self, fmt, tz=None):
629622
def __call__(self, x, pos=0):
630623
if x == 0:
631624
raise ValueError('DateFormatter found a value of x=0, which is '
632-
'an illegal date. This usually occurs because '
625+
'an illegal date; this usually occurs because '
633626
'you have not informed the axis that it is '
634627
'plotting dates, e.g., with ax.xaxis_date()')
635-
dt = num2date(x, self.tz)
636-
return self.strftime(dt, self.fmt)
628+
return num2date(x, self.tz).strftime(self.fmt)
637629

638630
def set_tzinfo(self, tz):
639631
self.tz = tz
640632

633+
@cbook.deprecated("3.0")
641634
def _replace_common_substr(self, s1, s2, sub1, sub2, replacement):
642635
"""Helper function for replacing substrings sub1 and sub2
643636
located at the same indexes in strings s1 and s2 respectively,
@@ -663,6 +656,7 @@ def _replace_common_substr(self, s1, s2, sub1, sub2, replacement):
663656

664657
return s1, s2
665658

659+
@cbook.deprecated("3.0")
666660
def strftime_pre_1900(self, dt, fmt=None):
667661
"""Call time.strftime for years before 1900 by rolling
668662
forward a multiple of 28 years.
@@ -720,6 +714,7 @@ def strftime_pre_1900(self, dt, fmt=None):
720714
"{0:02d}".format(dt.year % 100))
721715
return cbook.unicode_safe(s1)
722716

717+
@cbook.deprecated("3.0")
723718
def strftime(self, dt, fmt=None):
724719
"""
725720
Refer to documentation for :meth:`datetime.datetime.strftime`
@@ -764,10 +759,7 @@ def __call__(self, x, pos=0):
764759
ind = int(np.round(x))
765760
if ind >= len(self.t) or ind <= 0:
766761
return ''
767-
768-
dt = num2date(self.t[ind], self.tz)
769-
770-
return cbook.unicode_safe(dt.strftime(self.fmt))
762+
return num2date(self.t[ind], self.tz).strftime(self.fmt)
771763

772764

773765
class AutoDateFormatter(ticker.Formatter):
@@ -858,7 +850,7 @@ def __call__(self, x, pos=None):
858850
if scale >= locator_unit_scale),
859851
self.defaultfmt)
860852

861-
if isinstance(fmt, six.string_types):
853+
if isinstance(fmt, str):
862854
self._formatter = DateFormatter(fmt, self._tz)
863855
result = self._formatter(x, pos)
864856
elif callable(fmt):

0 commit comments

Comments
 (0)