@@ -53,15 +53,14 @@ def test_construction_with_alt(self):
5353 i .tz_localize (None ).asi8 , dtype = i .dtype , tz = 'US/Pacific' ))
5454
5555 def test_construction_index_with_mixed_timezones (self ):
56- # GH 11488
57- # no tz results in DatetimeIndex
56+ # gh-11488: no tz results in DatetimeIndex
5857 result = Index ([Timestamp ('2011-01-01' ),
5958 Timestamp ('2011-01-02' )], name = 'idx' )
6059 exp = DatetimeIndex ([Timestamp ('2011-01-01' ),
6160 Timestamp ('2011-01-02' )], name = 'idx' )
62- self .assert_index_equal (result , exp , exact = True )
63- self . assertTrue ( isinstance (result , DatetimeIndex ) )
64- self . assertIsNone ( result .tz )
61+ tm .assert_index_equal (result , exp , exact = True )
62+ assert isinstance (result , DatetimeIndex )
63+ assert result .tz is None
6564
6665 # same tz results in DatetimeIndex
6766 result = Index ([Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
@@ -70,10 +69,10 @@ def test_construction_index_with_mixed_timezones(self):
7069 exp = DatetimeIndex (
7170 [Timestamp ('2011-01-01 10:00' ), Timestamp ('2011-01-02 10:00' )
7271 ], tz = 'Asia/Tokyo' , name = 'idx' )
73- self .assert_index_equal (result , exp , exact = True )
74- self . assertTrue ( isinstance (result , DatetimeIndex ) )
75- self . assertIsNotNone ( result .tz )
76- self . assertEqual ( result .tz , exp .tz )
72+ tm .assert_index_equal (result , exp , exact = True )
73+ assert isinstance (result , DatetimeIndex )
74+ assert result .tz is not None
75+ assert result .tz == exp .tz
7776
7877 # same tz results in DatetimeIndex (DST)
7978 result = Index ([Timestamp ('2011-01-01 10:00' , tz = 'US/Eastern' ),
@@ -82,69 +81,69 @@ def test_construction_index_with_mixed_timezones(self):
8281 exp = DatetimeIndex ([Timestamp ('2011-01-01 10:00' ),
8382 Timestamp ('2011-08-01 10:00' )],
8483 tz = 'US/Eastern' , name = 'idx' )
85- self .assert_index_equal (result , exp , exact = True )
86- self . assertTrue ( isinstance (result , DatetimeIndex ) )
87- self . assertIsNotNone ( result .tz )
88- self . assertEqual ( result .tz , exp .tz )
84+ tm .assert_index_equal (result , exp , exact = True )
85+ assert isinstance (result , DatetimeIndex )
86+ assert result .tz is not None
87+ assert result .tz == exp .tz
8988
90- # different tz results in Index(dtype=object)
89+ # Different tz results in Index(dtype=object)
9190 result = Index ([Timestamp ('2011-01-01 10:00' ),
9291 Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
9392 name = 'idx' )
9493 exp = Index ([Timestamp ('2011-01-01 10:00' ),
9594 Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
9695 dtype = 'object' , name = 'idx' )
97- self .assert_index_equal (result , exp , exact = True )
98- self . assertFalse ( isinstance (result , DatetimeIndex ) )
96+ tm .assert_index_equal (result , exp , exact = True )
97+ assert not isinstance (result , DatetimeIndex )
9998
10099 result = Index ([Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
101100 Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
102101 name = 'idx' )
103102 exp = Index ([Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
104103 Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
105104 dtype = 'object' , name = 'idx' )
106- self .assert_index_equal (result , exp , exact = True )
107- self . assertFalse ( isinstance (result , DatetimeIndex ) )
105+ tm .assert_index_equal (result , exp , exact = True )
106+ assert not isinstance (result , DatetimeIndex )
108107
109108 # length = 1
110109 result = Index ([Timestamp ('2011-01-01' )], name = 'idx' )
111110 exp = DatetimeIndex ([Timestamp ('2011-01-01' )], name = 'idx' )
112- self .assert_index_equal (result , exp , exact = True )
113- self . assertTrue ( isinstance (result , DatetimeIndex ) )
114- self . assertIsNone ( result .tz )
111+ tm .assert_index_equal (result , exp , exact = True )
112+ assert isinstance (result , DatetimeIndex )
113+ assert result .tz is None
115114
116115 # length = 1 with tz
117116 result = Index (
118117 [Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' )], name = 'idx' )
119118 exp = DatetimeIndex ([Timestamp ('2011-01-01 10:00' )], tz = 'Asia/Tokyo' ,
120119 name = 'idx' )
121- self .assert_index_equal (result , exp , exact = True )
122- self . assertTrue ( isinstance (result , DatetimeIndex ) )
123- self . assertIsNotNone ( result .tz )
124- self . assertEqual ( result .tz , exp .tz )
120+ tm .assert_index_equal (result , exp , exact = True )
121+ assert isinstance (result , DatetimeIndex )
122+ assert result .tz is not None
123+ assert result .tz == exp .tz
125124
126125 def test_construction_index_with_mixed_timezones_with_NaT (self ):
127- # GH 11488
126+ # see gh- 11488
128127 result = Index ([pd .NaT , Timestamp ('2011-01-01' ),
129128 pd .NaT , Timestamp ('2011-01-02' )], name = 'idx' )
130129 exp = DatetimeIndex ([pd .NaT , Timestamp ('2011-01-01' ),
131130 pd .NaT , Timestamp ('2011-01-02' )], name = 'idx' )
132- self .assert_index_equal (result , exp , exact = True )
133- self . assertTrue ( isinstance (result , DatetimeIndex ) )
134- self . assertIsNone ( result .tz )
131+ tm .assert_index_equal (result , exp , exact = True )
132+ assert isinstance (result , DatetimeIndex )
133+ assert result .tz is None
135134
136- # same tz results in DatetimeIndex
135+ # Same tz results in DatetimeIndex
137136 result = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
138137 pd .NaT , Timestamp ('2011-01-02 10:00' ,
139138 tz = 'Asia/Tokyo' )],
140139 name = 'idx' )
141140 exp = DatetimeIndex ([pd .NaT , Timestamp ('2011-01-01 10:00' ),
142141 pd .NaT , Timestamp ('2011-01-02 10:00' )],
143142 tz = 'Asia/Tokyo' , name = 'idx' )
144- self .assert_index_equal (result , exp , exact = True )
145- self . assertTrue ( isinstance (result , DatetimeIndex ) )
146- self . assertIsNotNone ( result .tz )
147- self . assertEqual ( result .tz , exp .tz )
143+ tm .assert_index_equal (result , exp , exact = True )
144+ assert isinstance (result , DatetimeIndex )
145+ assert result .tz is not None
146+ assert result .tz == exp .tz
148147
149148 # same tz results in DatetimeIndex (DST)
150149 result = Index ([Timestamp ('2011-01-01 10:00' , tz = 'US/Eastern' ),
@@ -154,10 +153,10 @@ def test_construction_index_with_mixed_timezones_with_NaT(self):
154153 exp = DatetimeIndex ([Timestamp ('2011-01-01 10:00' ), pd .NaT ,
155154 Timestamp ('2011-08-01 10:00' )],
156155 tz = 'US/Eastern' , name = 'idx' )
157- self .assert_index_equal (result , exp , exact = True )
158- self . assertTrue ( isinstance (result , DatetimeIndex ) )
159- self . assertIsNotNone ( result .tz )
160- self . assertEqual ( result .tz , exp .tz )
156+ tm .assert_index_equal (result , exp , exact = True )
157+ assert isinstance (result , DatetimeIndex )
158+ assert result .tz is not None
159+ assert result .tz == exp .tz
161160
162161 # different tz results in Index(dtype=object)
163162 result = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' ),
@@ -167,32 +166,33 @@ def test_construction_index_with_mixed_timezones_with_NaT(self):
167166 exp = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' ),
168167 pd .NaT , Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
169168 dtype = 'object' , name = 'idx' )
170- self .assert_index_equal (result , exp , exact = True )
171- self . assertFalse ( isinstance (result , DatetimeIndex ) )
169+ tm .assert_index_equal (result , exp , exact = True )
170+ assert not isinstance (result , DatetimeIndex )
172171
173172 result = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
174173 pd .NaT , Timestamp ('2011-01-02 10:00' ,
175174 tz = 'US/Eastern' )], name = 'idx' )
176175 exp = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
177176 pd .NaT , Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
178177 dtype = 'object' , name = 'idx' )
179- self .assert_index_equal (result , exp , exact = True )
180- self . assertFalse ( isinstance (result , DatetimeIndex ) )
178+ tm .assert_index_equal (result , exp , exact = True )
179+ assert not isinstance (result , DatetimeIndex )
181180
182181 # all NaT
183182 result = Index ([pd .NaT , pd .NaT ], name = 'idx' )
184183 exp = DatetimeIndex ([pd .NaT , pd .NaT ], name = 'idx' )
185- self .assert_index_equal (result , exp , exact = True )
186- self . assertTrue ( isinstance (result , DatetimeIndex ) )
187- self . assertIsNone ( result .tz )
184+ tm .assert_index_equal (result , exp , exact = True )
185+ assert isinstance (result , DatetimeIndex )
186+ assert result .tz is None
188187
189188 # all NaT with tz
190189 result = Index ([pd .NaT , pd .NaT ], tz = 'Asia/Tokyo' , name = 'idx' )
191190 exp = DatetimeIndex ([pd .NaT , pd .NaT ], tz = 'Asia/Tokyo' , name = 'idx' )
192- self .assert_index_equal (result , exp , exact = True )
193- self .assertTrue (isinstance (result , DatetimeIndex ))
194- self .assertIsNotNone (result .tz )
195- self .assertEqual (result .tz , exp .tz )
191+
192+ tm .assert_index_equal (result , exp , exact = True )
193+ assert isinstance (result , DatetimeIndex )
194+ assert result .tz is not None
195+ assert result .tz == exp .tz
196196
197197 def test_construction_dti_with_mixed_timezones (self ):
198198 # GH 11488 (not changed, added explicit tests)
0 commit comments