@@ -507,11 +507,7 @@ def _create_auto_date_locator(date1, date2):
507
507
assert list (map (str , mdates .num2date (locator ()))) == expected
508
508
509
509
510
- @pytest .mark .pytz
511
- @pytest .mark .skipif (not __has_pytz (), reason = "Requires pytz" )
512
510
def test_auto_date_locator_intmult_tz ():
513
- import pytz
514
-
515
511
def _create_auto_date_locator (date1 , date2 , tz ):
516
512
locator = mdates .AutoDateLocator (interval_multiples = True , tz = tz )
517
513
locator .create_dummy_axis ()
@@ -572,8 +568,8 @@ def _create_auto_date_locator(date1, date2, tz):
572
568
]
573
569
)
574
570
575
- tz = pytz . timezone ( 'US /Pacific' )
576
- d1 = tz . localize ( datetime .datetime (1997 , 1 , 1 ) )
571
+ tz = dateutil . tz . gettz ( 'Canada /Pacific' )
572
+ d1 = datetime .datetime (1997 , 1 , 1 , tzinfo = tz )
577
573
for t_delta , expected in results :
578
574
with rc_context ({'_internal.classic_mode' : False }):
579
575
d2 = d1 + t_delta
@@ -726,6 +722,29 @@ def attach_tz(dt, zi):
726
722
_test_rrulewrapper (attach_tz , pytz .timezone )
727
723
728
724
725
+ @pytest .mark .pytz
726
+ @pytest .mark .skipif (not __has_pytz (), reason = "Requires pytz" )
727
+ def test_yearlocator_pytz ():
728
+ import pytz
729
+
730
+ tz = pytz .timezone ('America/New_York' )
731
+ x = [datetime .datetime (2010 , 1 , 1 ).astimezone (tz )
732
+ + datetime .timedelta (i ) for i in range (2000 )]
733
+ locator = mdates .AutoDateLocator (interval_multiples = False , tz = tz )
734
+ locator .create_dummy_axis ()
735
+ locator .set_view_interval (mdates .date2num (x [0 ]),
736
+ mdates .date2num (x [- 1 ]))
737
+
738
+ np .testing .assert_allclose ([734138.20833333 , 734503.20833333 ,
739
+ 734869.20833333 , 735234.20833333 ,
740
+ 735599.20833333 ], locator ())
741
+ expected = ['2011-01-01 00:00:00-05:00' , '2012-01-01 00:00:00-05:00' ,
742
+ '2013-01-01 00:00:00-05:00' , '2014-01-01 00:00:00-05:00' ,
743
+ '2015-01-01 00:00:00-05:00' ]
744
+ st = list (map (str , mdates .num2date (locator (), tz = tz )))
745
+ assert st == expected
746
+
747
+
729
748
def test_DayLocator ():
730
749
with pytest .raises (ValueError ):
731
750
mdates .DayLocator (interval = - 1 )
0 commit comments