@@ -1624,9 +1624,10 @@ def __init__(self, base=1, month=1, day=1, tz=None):
1624
1624
'minute' : 0 ,
1625
1625
'second' : 0 ,
1626
1626
}
1627
- # Note that tzinfo does not work with pytz timezones, and
1628
- # astimezone doesn't work unless a datetime has timezone info (for
1629
- # py3.5). So the user should provide time-zone aware dates.
1627
+ if not hasattr (tz , 'localize' ):
1628
+ # if tz is pytz, we need to do this w/ the localize fcn,
1629
+ # otherwise datetime.replace works fine...
1630
+ self .replaced ['tzinfo' ] = tz
1630
1631
1631
1632
def __call__ (self ):
1632
1633
# if no data have been set, this will tank with a ValueError
@@ -1642,17 +1643,24 @@ def tick_values(self, vmin, vmax):
1642
1643
ymax = self .base .ge (vmax .year ) * self .base .step
1643
1644
1644
1645
vmin = vmin .replace (year = ymin , ** self .replaced )
1645
- try :
1646
- ticks = [vmin .astimezone (self .tz )]
1647
- except ValueError as e :
1648
- raise ValueError ('naive datetime objects cannot be used '
1649
- 'with matplotlib for python < 3.6; ' ) from e
1646
+ if hasattr (self .tz , 'localize' ):
1647
+ # look after pytz
1648
+ if not vmin .tzinfo :
1649
+ vmin = self .tz .localize (vmin , is_dst = True )
1650
+
1651
+ ticks = [vmin ]
1652
+
1650
1653
while True :
1651
1654
dt = ticks [- 1 ]
1652
1655
if dt .year >= ymax :
1653
1656
return date2num (ticks )
1654
1657
year = dt .year + self .base .step
1655
- dt = dt .replace (year = year , ** self .replaced ).astimezone (self .tz )
1658
+ dt = dt .replace (year = year , ** self .replaced )
1659
+ if hasattr (self .tz , 'localize' ):
1660
+ # look after pytz
1661
+ if not dt .tzinfo :
1662
+ dt = self .tz .localize (dt , is_dst = True )
1663
+
1656
1664
ticks .append (dt )
1657
1665
1658
1666
def autoscale (self ):
0 commit comments