@@ -271,6 +271,7 @@ def test_tz_convert_roundtrip(self, tz_aware_fixture):
271
271
tm .assert_index_equal (reset , expected )
272
272
assert reset .tzinfo is None
273
273
expected = converted .tz_convert ("UTC" ).tz_localize (None )
274
+ expected = expected ._with_freq ("infer" )
274
275
tm .assert_index_equal (reset , expected )
275
276
276
277
def test_dti_tz_convert_tzlocal (self ):
@@ -352,8 +353,9 @@ def test_dti_tz_localize_ambiguous_infer(self, tz):
352
353
]
353
354
di = DatetimeIndex (times )
354
355
localized = di .tz_localize (tz , ambiguous = "infer" )
355
- tm .assert_index_equal (dr , localized )
356
- tm .assert_index_equal (dr , DatetimeIndex (times , tz = tz , ambiguous = "infer" ))
356
+ expected = dr ._with_freq (None )
357
+ tm .assert_index_equal (expected , localized )
358
+ tm .assert_index_equal (expected , DatetimeIndex (times , tz = tz , ambiguous = "infer" ))
357
359
358
360
# When there is no dst transition, nothing special happens
359
361
dr = date_range (datetime (2011 , 6 , 1 , 0 ), periods = 10 , freq = pd .offsets .Hour ())
@@ -458,15 +460,16 @@ def test_dti_tz_localize_roundtrip(self, tz_aware_fixture):
458
460
localized .tz_localize (tz )
459
461
reset = localized .tz_localize (None )
460
462
assert reset .tzinfo is None
461
- tm .assert_index_equal (reset , idx )
463
+ expected = idx ._with_freq (None )
464
+ tm .assert_index_equal (reset , expected )
462
465
463
466
def test_dti_tz_localize_naive (self ):
464
467
rng = date_range ("1/1/2011" , periods = 100 , freq = "H" )
465
468
466
469
conv = rng .tz_localize ("US/Pacific" )
467
470
exp = date_range ("1/1/2011" , periods = 100 , freq = "H" , tz = "US/Pacific" )
468
471
469
- tm .assert_index_equal (conv , exp )
472
+ tm .assert_index_equal (conv , exp . _with_freq ( None ) )
470
473
471
474
def test_dti_tz_localize_tzlocal (self ):
472
475
# GH#13583
@@ -526,8 +529,9 @@ def test_dti_tz_localize_ambiguous_flags(self, tz):
526
529
di = DatetimeIndex (times )
527
530
is_dst = [1 , 1 , 0 , 0 , 0 ]
528
531
localized = di .tz_localize (tz , ambiguous = is_dst )
529
- tm .assert_index_equal (dr , localized )
530
- tm .assert_index_equal (dr , DatetimeIndex (times , tz = tz , ambiguous = is_dst ))
532
+ expected = dr ._with_freq (None )
533
+ tm .assert_index_equal (expected , localized )
534
+ tm .assert_index_equal (expected , DatetimeIndex (times , tz = tz , ambiguous = is_dst ))
531
535
532
536
localized = di .tz_localize (tz , ambiguous = np .array (is_dst ))
533
537
tm .assert_index_equal (dr , localized )
@@ -703,9 +707,9 @@ def test_dti_tz_localize_nonexistent_shift_invalid(self, offset, tz_type):
703
707
def test_normalize_tz (self ):
704
708
rng = date_range ("1/1/2000 9:30" , periods = 10 , freq = "D" , tz = "US/Eastern" )
705
709
706
- result = rng .normalize ()
710
+ result = rng .normalize () # does not preserve freq
707
711
expected = date_range ("1/1/2000" , periods = 10 , freq = "D" , tz = "US/Eastern" )
708
- tm .assert_index_equal (result , expected )
712
+ tm .assert_index_equal (result , expected . _with_freq ( None ) )
709
713
710
714
assert result .is_normalized
711
715
assert not rng .is_normalized
@@ -720,9 +724,9 @@ def test_normalize_tz(self):
720
724
assert not rng .is_normalized
721
725
722
726
rng = date_range ("1/1/2000 9:30" , periods = 10 , freq = "D" , tz = tzlocal ())
723
- result = rng .normalize ()
727
+ result = rng .normalize () # does not preserve freq
724
728
expected = date_range ("1/1/2000" , periods = 10 , freq = "D" , tz = tzlocal ())
725
- tm .assert_index_equal (result , expected )
729
+ tm .assert_index_equal (result , expected . _with_freq ( None ) )
726
730
727
731
assert result .is_normalized
728
732
assert not rng .is_normalized
@@ -746,6 +750,7 @@ def test_normalize_tz_local(self, timezone):
746
750
747
751
result = rng .normalize ()
748
752
expected = date_range ("1/1/2000" , periods = 10 , freq = "D" , tz = tzlocal ())
753
+ expected = expected ._with_freq (None )
749
754
tm .assert_index_equal (result , expected )
750
755
751
756
assert result .is_normalized
@@ -777,10 +782,8 @@ def test_dti_constructor_with_fixed_tz(self):
777
782
@pytest .mark .parametrize ("tzstr" , ["US/Eastern" , "dateutil/US/Eastern" ])
778
783
def test_dti_convert_datetime_list (self , tzstr ):
779
784
dr = date_range ("2012-06-02" , periods = 10 , tz = tzstr , name = "foo" )
780
- dr2 = DatetimeIndex (list (dr ), name = "foo" )
785
+ dr2 = DatetimeIndex (list (dr ), name = "foo" , freq = "D" )
781
786
tm .assert_index_equal (dr , dr2 )
782
- assert dr .tz == dr2 .tz
783
- assert dr2 .name == "foo"
784
787
785
788
def test_dti_construction_univalent (self ):
786
789
rng = date_range ("03/12/2012 00:00" , periods = 10 , freq = "W-FRI" , tz = "US/Eastern" )
@@ -803,6 +806,7 @@ def test_dti_tz_constructors(self, tzstr):
803
806
804
807
idx1 = to_datetime (arr ).tz_localize (tzstr )
805
808
idx2 = pd .date_range (start = "2005-11-10 08:00:00" , freq = "H" , periods = 2 , tz = tzstr )
809
+ idx2 = idx2 ._with_freq (None ) # the others all have freq=None
806
810
idx3 = DatetimeIndex (arr , tz = tzstr )
807
811
idx4 = DatetimeIndex (np .array (arr ), tz = tzstr )
808
812
@@ -913,7 +917,7 @@ def test_date_range_localize(self):
913
917
rng3 = date_range ("3/11/2012 03:00" , periods = 15 , freq = "H" )
914
918
rng3 = rng3 .tz_localize ("US/Eastern" )
915
919
916
- tm .assert_index_equal (rng , rng3 )
920
+ tm .assert_index_equal (rng . _with_freq ( None ) , rng3 )
917
921
918
922
# DST transition time
919
923
val = rng [0 ]
@@ -926,7 +930,9 @@ def test_date_range_localize(self):
926
930
927
931
# Right before the DST transition
928
932
rng = date_range ("3/11/2012 00:00" , periods = 2 , freq = "H" , tz = "US/Eastern" )
929
- rng2 = DatetimeIndex (["3/11/2012 00:00" , "3/11/2012 01:00" ], tz = "US/Eastern" )
933
+ rng2 = DatetimeIndex (
934
+ ["3/11/2012 00:00" , "3/11/2012 01:00" ], tz = "US/Eastern" , freq = "H"
935
+ )
930
936
tm .assert_index_equal (rng , rng2 )
931
937
exp = Timestamp ("3/11/2012 00:00" , tz = "US/Eastern" )
932
938
assert exp .hour == 0
0 commit comments