@@ -351,52 +351,51 @@ def test_constructor_coverage(self):
351
351
freq = 'B' )
352
352
pytest .raises (ValueError , DatetimeIndex , periods = 10 , freq = 'D' )
353
353
354
- def test_constructor_datetime64_tzformat ( self ):
355
- # see gh-6572: ISO 8601 format results in pytz.FixedOffset
356
- for freq in [ 'AS' , 'W-SUN' ]:
357
- idx = date_range ('2013-01-01T00:00:00-05:00' ,
358
- '2016-01-01T23:59:59-05:00' , freq = freq )
359
- expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
360
- freq = freq , tz = pytz .FixedOffset (- 300 ))
361
- tm .assert_index_equal (idx , expected )
362
- # Unable to use `US/Eastern` because of DST
363
- expected_i8 = date_range ('2013-01-01T00:00:00' ,
364
- '2016-01-01T23:59:59' , freq = freq ,
365
- tz = 'America/Lima' )
366
- tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
367
-
368
- idx = date_range ('2013-01-01T00:00:00+09:00' ,
369
- '2016-01-01T23:59:59+09:00' , freq = freq )
370
- expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
371
- freq = freq , tz = pytz .FixedOffset (540 ))
372
- tm .assert_index_equal (idx , expected )
373
- expected_i8 = date_range ('2013-01-01T00:00:00' ,
374
- '2016-01-01T23:59:59' , freq = freq ,
375
- tz = 'Asia/Tokyo' )
376
- tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
354
+ @ pytest . mark . parametrize ( 'freq' , [ 'AS' , 'W-SUN' ])
355
+ def test_constructor_datetime64_tzformat ( self , freq ):
356
+ # see GH#6572: ISO 8601 format results in pytz.FixedOffset
357
+ idx = date_range ('2013-01-01T00:00:00-05:00' ,
358
+ '2016-01-01T23:59:59-05:00' , freq = freq )
359
+ expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
360
+ freq = freq , tz = pytz .FixedOffset (- 300 ))
361
+ tm .assert_index_equal (idx , expected )
362
+ # Unable to use `US/Eastern` because of DST
363
+ expected_i8 = date_range ('2013-01-01T00:00:00' ,
364
+ '2016-01-01T23:59:59' , freq = freq ,
365
+ tz = 'America/Lima' )
366
+ tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
367
+
368
+ idx = date_range ('2013-01-01T00:00:00+09:00' ,
369
+ '2016-01-01T23:59:59+09:00' , freq = freq )
370
+ expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
371
+ freq = freq , tz = pytz .FixedOffset (540 ))
372
+ tm .assert_index_equal (idx , expected )
373
+ expected_i8 = date_range ('2013-01-01T00:00:00' ,
374
+ '2016-01-01T23:59:59' , freq = freq ,
375
+ tz = 'Asia/Tokyo' )
376
+ tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
377
377
378
378
# Non ISO 8601 format results in dateutil.tz.tzoffset
379
- for freq in ['AS' , 'W-SUN' ]:
380
- idx = date_range ('2013/1/1 0:00:00-5:00' , '2016/1/1 23:59:59-5:00' ,
381
- freq = freq )
382
- expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
383
- freq = freq , tz = pytz .FixedOffset (- 300 ))
384
- tm .assert_index_equal (idx , expected )
385
- # Unable to use `US/Eastern` because of DST
386
- expected_i8 = date_range ('2013-01-01T00:00:00' ,
387
- '2016-01-01T23:59:59' , freq = freq ,
388
- tz = 'America/Lima' )
389
- tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
390
-
391
- idx = date_range ('2013/1/1 0:00:00+9:00' ,
392
- '2016/1/1 23:59:59+09:00' , freq = freq )
393
- expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
394
- freq = freq , tz = pytz .FixedOffset (540 ))
395
- tm .assert_index_equal (idx , expected )
396
- expected_i8 = date_range ('2013-01-01T00:00:00' ,
397
- '2016-01-01T23:59:59' , freq = freq ,
398
- tz = 'Asia/Tokyo' )
399
- tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
379
+ idx = date_range ('2013/1/1 0:00:00-5:00' , '2016/1/1 23:59:59-5:00' ,
380
+ freq = freq )
381
+ expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
382
+ freq = freq , tz = pytz .FixedOffset (- 300 ))
383
+ tm .assert_index_equal (idx , expected )
384
+ # Unable to use `US/Eastern` because of DST
385
+ expected_i8 = date_range ('2013-01-01T00:00:00' ,
386
+ '2016-01-01T23:59:59' , freq = freq ,
387
+ tz = 'America/Lima' )
388
+ tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
389
+
390
+ idx = date_range ('2013/1/1 0:00:00+9:00' ,
391
+ '2016/1/1 23:59:59+09:00' , freq = freq )
392
+ expected = date_range ('2013-01-01T00:00:00' , '2016-01-01T23:59:59' ,
393
+ freq = freq , tz = pytz .FixedOffset (540 ))
394
+ tm .assert_index_equal (idx , expected )
395
+ expected_i8 = date_range ('2013-01-01T00:00:00' ,
396
+ '2016-01-01T23:59:59' , freq = freq ,
397
+ tz = 'Asia/Tokyo' )
398
+ tm .assert_numpy_array_equal (idx .asi8 , expected_i8 .asi8 )
400
399
401
400
def test_constructor_dtype (self ):
402
401
@@ -451,36 +450,35 @@ def test_dti_constructor_preserve_dti_freq(self):
451
450
rng2 = DatetimeIndex (rng )
452
451
assert rng .freq == rng2 .freq
453
452
454
- def test_dti_constructor_years_only (self ):
453
+ @pytest .mark .parametrize ('tz' , [None , 'UTC' , 'Asia/Tokyo' ,
454
+ 'dateutil/US/Pacific' ])
455
+ def test_dti_constructor_years_only (self , tz ):
455
456
# GH 6961
456
- for tz in [None , 'UTC' , 'Asia/Tokyo' , 'dateutil/US/Pacific' ]:
457
- rng1 = date_range ('2014' , '2015' , freq = 'M' , tz = tz )
458
- expected1 = date_range ('2014-01-31' , '2014-12-31' , freq = 'M' , tz = tz )
457
+ rng1 = date_range ('2014' , '2015' , freq = 'M' , tz = tz )
458
+ expected1 = date_range ('2014-01-31' , '2014-12-31' , freq = 'M' , tz = tz )
459
459
460
- rng2 = date_range ('2014' , '2015' , freq = 'MS' , tz = tz )
461
- expected2 = date_range ('2014-01-01' , '2015-01-01' , freq = 'MS' ,
462
- tz = tz )
460
+ rng2 = date_range ('2014' , '2015' , freq = 'MS' , tz = tz )
461
+ expected2 = date_range ('2014-01-01' , '2015-01-01' , freq = 'MS' , tz = tz )
463
462
464
- rng3 = date_range ('2014' , '2020' , freq = 'A' , tz = tz )
465
- expected3 = date_range ('2014-12-31' , '2019-12-31' , freq = 'A' , tz = tz )
463
+ rng3 = date_range ('2014' , '2020' , freq = 'A' , tz = tz )
464
+ expected3 = date_range ('2014-12-31' , '2019-12-31' , freq = 'A' , tz = tz )
466
465
467
- rng4 = date_range ('2014' , '2020' , freq = 'AS' , tz = tz )
468
- expected4 = date_range ('2014-01-01' , '2020-01-01' , freq = 'AS' ,
469
- tz = tz )
466
+ rng4 = date_range ('2014' , '2020' , freq = 'AS' , tz = tz )
467
+ expected4 = date_range ('2014-01-01' , '2020-01-01' , freq = 'AS' , tz = tz )
470
468
471
- for rng , expected in [(rng1 , expected1 ), (rng2 , expected2 ),
472
- (rng3 , expected3 ), (rng4 , expected4 )]:
473
- tm .assert_index_equal (rng , expected )
469
+ for rng , expected in [(rng1 , expected1 ), (rng2 , expected2 ),
470
+ (rng3 , expected3 ), (rng4 , expected4 )]:
471
+ tm .assert_index_equal (rng , expected )
474
472
475
- def test_dti_constructor_small_int (self ):
473
+ @pytest .mark .parametrize ('dtype' , [np .int64 , np .int32 , np .int16 , np .int8 ])
474
+ def test_dti_constructor_small_int (self , dtype ):
476
475
# GH 13721
477
476
exp = DatetimeIndex (['1970-01-01 00:00:00.00000000' ,
478
477
'1970-01-01 00:00:00.00000001' ,
479
478
'1970-01-01 00:00:00.00000002' ])
480
479
481
- for dtype in [np .int64 , np .int32 , np .int16 , np .int8 ]:
482
- arr = np .array ([0 , 10 , 20 ], dtype = dtype )
483
- tm .assert_index_equal (DatetimeIndex (arr ), exp )
480
+ arr = np .array ([0 , 10 , 20 ], dtype = dtype )
481
+ tm .assert_index_equal (DatetimeIndex (arr ), exp )
484
482
485
483
def test_ctor_str_intraday (self ):
486
484
rng = DatetimeIndex (['1-1-2000 00:00:01' ])
@@ -499,7 +497,7 @@ def test_index_cast_datetime64_other_units(self):
499
497
assert (idx .values == conversion .ensure_datetime64ns (arr )).all ()
500
498
501
499
def test_constructor_int64_nocopy (self ):
502
- # #1624
500
+ # GH #1624
503
501
arr = np .arange (1000 , dtype = np .int64 )
504
502
index = DatetimeIndex (arr )
505
503
@@ -512,19 +510,17 @@ def test_constructor_int64_nocopy(self):
512
510
arr [50 :100 ] = - 1
513
511
assert (index .asi8 [50 :100 ] != - 1 ).all ()
514
512
515
- def test_from_freq_recreate_from_data (self ):
516
- freqs = ['M' , 'Q' , 'A' , 'D' , 'B' , 'BH' , 'T' , 'S' , 'L' , 'U' , 'H' , 'N' ,
517
- 'C' ]
518
-
519
- for f in freqs :
520
- org = DatetimeIndex (start = '2001/02/01 09:00' , freq = f , periods = 1 )
521
- idx = DatetimeIndex (org , freq = f )
522
- tm .assert_index_equal (idx , org )
523
-
524
- org = DatetimeIndex (start = '2001/02/01 09:00' , freq = f ,
525
- tz = 'US/Pacific' , periods = 1 )
526
- idx = DatetimeIndex (org , freq = f , tz = 'US/Pacific' )
527
- tm .assert_index_equal (idx , org )
513
+ @pytest .mark .parametrize ('freq' , ['M' , 'Q' , 'A' , 'D' , 'B' , 'BH' ,
514
+ 'T' , 'S' , 'L' , 'U' , 'H' , 'N' , 'C' ])
515
+ def test_from_freq_recreate_from_data (self , freq ):
516
+ org = DatetimeIndex (start = '2001/02/01 09:00' , freq = freq , periods = 1 )
517
+ idx = DatetimeIndex (org , freq = freq )
518
+ tm .assert_index_equal (idx , org )
519
+
520
+ org = DatetimeIndex (start = '2001/02/01 09:00' , freq = freq ,
521
+ tz = 'US/Pacific' , periods = 1 )
522
+ idx = DatetimeIndex (org , freq = freq , tz = 'US/Pacific' )
523
+ tm .assert_index_equal (idx , org )
528
524
529
525
def test_datetimeindex_constructor_misc (self ):
530
526
arr = ['1/1/2005' , '1/2/2005' , 'Jn 3, 2005' , '2005-01-04' ]
0 commit comments