@@ -271,6 +271,7 @@ def test_tz_convert_roundtrip(self, tz_aware_fixture):
271271 tm .assert_index_equal (reset , expected )
272272 assert reset .tzinfo is None
273273 expected = converted .tz_convert ("UTC" ).tz_localize (None )
274+ expected = expected ._with_freq ("infer" )
274275 tm .assert_index_equal (reset , expected )
275276
276277 def test_dti_tz_convert_tzlocal (self ):
@@ -352,8 +353,9 @@ def test_dti_tz_localize_ambiguous_infer(self, tz):
352353 ]
353354 di = DatetimeIndex (times )
354355 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" ))
357359
358360 # When there is no dst transition, nothing special happens
359361 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):
458460 localized .tz_localize (tz )
459461 reset = localized .tz_localize (None )
460462 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 )
462465
463466 def test_dti_tz_localize_naive (self ):
464467 rng = date_range ("1/1/2011" , periods = 100 , freq = "H" )
465468
466469 conv = rng .tz_localize ("US/Pacific" )
467470 exp = date_range ("1/1/2011" , periods = 100 , freq = "H" , tz = "US/Pacific" )
468471
469- tm .assert_index_equal (conv , exp )
472+ tm .assert_index_equal (conv , exp . _with_freq ( None ) )
470473
471474 def test_dti_tz_localize_tzlocal (self ):
472475 # GH#13583
@@ -526,8 +529,9 @@ def test_dti_tz_localize_ambiguous_flags(self, tz):
526529 di = DatetimeIndex (times )
527530 is_dst = [1 , 1 , 0 , 0 , 0 ]
528531 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 ))
531535
532536 localized = di .tz_localize (tz , ambiguous = np .array (is_dst ))
533537 tm .assert_index_equal (dr , localized )
@@ -703,9 +707,9 @@ def test_dti_tz_localize_nonexistent_shift_invalid(self, offset, tz_type):
703707 def test_normalize_tz (self ):
704708 rng = date_range ("1/1/2000 9:30" , periods = 10 , freq = "D" , tz = "US/Eastern" )
705709
706- result = rng .normalize ()
710+ result = rng .normalize () # does not preserve freq
707711 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 ) )
709713
710714 assert result .is_normalized
711715 assert not rng .is_normalized
@@ -720,9 +724,9 @@ def test_normalize_tz(self):
720724 assert not rng .is_normalized
721725
722726 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
724728 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 ) )
726730
727731 assert result .is_normalized
728732 assert not rng .is_normalized
@@ -746,6 +750,7 @@ def test_normalize_tz_local(self, timezone):
746750
747751 result = rng .normalize ()
748752 expected = date_range ("1/1/2000" , periods = 10 , freq = "D" , tz = tzlocal ())
753+ expected = expected ._with_freq (None )
749754 tm .assert_index_equal (result , expected )
750755
751756 assert result .is_normalized
@@ -777,10 +782,8 @@ def test_dti_constructor_with_fixed_tz(self):
777782 @pytest .mark .parametrize ("tzstr" , ["US/Eastern" , "dateutil/US/Eastern" ])
778783 def test_dti_convert_datetime_list (self , tzstr ):
779784 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" )
781786 tm .assert_index_equal (dr , dr2 )
782- assert dr .tz == dr2 .tz
783- assert dr2 .name == "foo"
784787
785788 def test_dti_construction_univalent (self ):
786789 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):
803806
804807 idx1 = to_datetime (arr ).tz_localize (tzstr )
805808 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
806810 idx3 = DatetimeIndex (arr , tz = tzstr )
807811 idx4 = DatetimeIndex (np .array (arr ), tz = tzstr )
808812
@@ -913,7 +917,7 @@ def test_date_range_localize(self):
913917 rng3 = date_range ("3/11/2012 03:00" , periods = 15 , freq = "H" )
914918 rng3 = rng3 .tz_localize ("US/Eastern" )
915919
916- tm .assert_index_equal (rng , rng3 )
920+ tm .assert_index_equal (rng . _with_freq ( None ) , rng3 )
917921
918922 # DST transition time
919923 val = rng [0 ]
@@ -926,7 +930,9 @@ def test_date_range_localize(self):
926930
927931 # Right before the DST transition
928932 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+ )
930936 tm .assert_index_equal (rng , rng2 )
931937 exp = Timestamp ("3/11/2012 00:00" , tz = "US/Eastern" )
932938 assert exp .hour == 0
0 commit comments