@@ -354,25 +354,51 @@ def test_range_bug(self):
354
354
def test_range_tz_pytz (self ):
355
355
# GH 2906
356
356
tm ._skip_if_no_pytz ()
357
- from pytz import timezone as tz
357
+ from pytz import timezone
358
358
359
- start = datetime (2011 , 1 , 1 , tzinfo = tz ('US/Eastern' ))
360
- end = datetime (2011 , 1 , 3 , tzinfo = tz ('US/Eastern' ))
359
+ tz = timezone ('US/Eastern' )
360
+ start = tz .localize (datetime (2011 , 1 , 1 ))
361
+ end = tz .localize (datetime (2011 , 1 , 3 ))
361
362
362
363
dr = date_range (start = start , periods = 3 )
363
- self .assertEqual (dr .tz , tz ( 'US/Eastern' ) )
364
+ self .assertEqual (dr .tz . zone , tz . zone )
364
365
self .assertEqual (dr [0 ], start )
365
366
self .assertEqual (dr [2 ], end )
366
367
367
368
dr = date_range (end = end , periods = 3 )
368
- self .assertEqual (dr .tz , tz ( 'US/Eastern' ) )
369
+ self .assertEqual (dr .tz . zone , tz . zone )
369
370
self .assertEqual (dr [0 ], start )
370
371
self .assertEqual (dr [2 ], end )
371
372
372
373
dr = date_range (start = start , end = end )
373
- self .assertEqual (dr .tz , tz ( 'US/Eastern' ) )
374
+ self .assertEqual (dr .tz . zone , tz . zone )
374
375
self .assertEqual (dr [0 ], start )
375
376
self .assertEqual (dr [2 ], end )
377
+
378
+ def test_range_tz_dst_straddle_pytz (self ):
379
+
380
+ tm ._skip_if_no_pytz ()
381
+ from pytz import timezone
382
+ tz = timezone ('US/Eastern' )
383
+ dates = [(tz .localize (datetime (2014 , 3 , 6 )),
384
+ tz .localize (datetime (2014 , 3 , 12 ))),
385
+ (tz .localize (datetime (2013 , 11 , 1 )),
386
+ tz .localize (datetime (2013 , 11 , 6 )))]
387
+ for (start , end ) in dates :
388
+ dr = date_range (start , end , freq = 'D' )
389
+ self .assertEqual (dr [0 ], start )
390
+ self .assertEqual (dr [- 1 ], end )
391
+ self .assertEqual (np .all (dr .hour == 0 ), True )
392
+
393
+ dr = date_range (start , end , freq = 'D' , tz = 'US/Eastern' )
394
+ self .assertEqual (dr [0 ], start )
395
+ self .assertEqual (dr [- 1 ], end )
396
+ self .assertEqual (np .all (dr .hour == 0 ), True )
397
+
398
+ dr = date_range (start .replace (tzinfo = None ), end .replace (tzinfo = None ), freq = 'D' , tz = 'US/Eastern' )
399
+ self .assertEqual (dr [0 ], start )
400
+ self .assertEqual (dr [- 1 ], end )
401
+ self .assertEqual (np .all (dr .hour == 0 ), True )
376
402
377
403
def test_range_tz_dateutil (self ):
378
404
# GH 2906
0 commit comments