@@ -53,15 +53,14 @@ def test_construction_with_alt(self):
53
53
i .tz_localize (None ).asi8 , dtype = i .dtype , tz = 'US/Pacific' ))
54
54
55
55
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
58
57
result = Index ([Timestamp ('2011-01-01' ),
59
58
Timestamp ('2011-01-02' )], name = 'idx' )
60
59
exp = DatetimeIndex ([Timestamp ('2011-01-01' ),
61
60
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
65
64
66
65
# same tz results in DatetimeIndex
67
66
result = Index ([Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
@@ -70,10 +69,10 @@ def test_construction_index_with_mixed_timezones(self):
70
69
exp = DatetimeIndex (
71
70
[Timestamp ('2011-01-01 10:00' ), Timestamp ('2011-01-02 10:00' )
72
71
], 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
77
76
78
77
# same tz results in DatetimeIndex (DST)
79
78
result = Index ([Timestamp ('2011-01-01 10:00' , tz = 'US/Eastern' ),
@@ -82,69 +81,69 @@ def test_construction_index_with_mixed_timezones(self):
82
81
exp = DatetimeIndex ([Timestamp ('2011-01-01 10:00' ),
83
82
Timestamp ('2011-08-01 10:00' )],
84
83
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
89
88
90
- # different tz results in Index(dtype=object)
89
+ # Different tz results in Index(dtype=object)
91
90
result = Index ([Timestamp ('2011-01-01 10:00' ),
92
91
Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
93
92
name = 'idx' )
94
93
exp = Index ([Timestamp ('2011-01-01 10:00' ),
95
94
Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
96
95
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 )
99
98
100
99
result = Index ([Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
101
100
Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
102
101
name = 'idx' )
103
102
exp = Index ([Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
104
103
Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
105
104
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 )
108
107
109
108
# length = 1
110
109
result = Index ([Timestamp ('2011-01-01' )], name = 'idx' )
111
110
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
115
114
116
115
# length = 1 with tz
117
116
result = Index (
118
117
[Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' )], name = 'idx' )
119
118
exp = DatetimeIndex ([Timestamp ('2011-01-01 10:00' )], tz = 'Asia/Tokyo' ,
120
119
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
125
124
126
125
def test_construction_index_with_mixed_timezones_with_NaT (self ):
127
- # GH 11488
126
+ # see gh- 11488
128
127
result = Index ([pd .NaT , Timestamp ('2011-01-01' ),
129
128
pd .NaT , Timestamp ('2011-01-02' )], name = 'idx' )
130
129
exp = DatetimeIndex ([pd .NaT , Timestamp ('2011-01-01' ),
131
130
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
135
134
136
- # same tz results in DatetimeIndex
135
+ # Same tz results in DatetimeIndex
137
136
result = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
138
137
pd .NaT , Timestamp ('2011-01-02 10:00' ,
139
138
tz = 'Asia/Tokyo' )],
140
139
name = 'idx' )
141
140
exp = DatetimeIndex ([pd .NaT , Timestamp ('2011-01-01 10:00' ),
142
141
pd .NaT , Timestamp ('2011-01-02 10:00' )],
143
142
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
148
147
149
148
# same tz results in DatetimeIndex (DST)
150
149
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):
154
153
exp = DatetimeIndex ([Timestamp ('2011-01-01 10:00' ), pd .NaT ,
155
154
Timestamp ('2011-08-01 10:00' )],
156
155
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
161
160
162
161
# different tz results in Index(dtype=object)
163
162
result = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' ),
@@ -167,32 +166,33 @@ def test_construction_index_with_mixed_timezones_with_NaT(self):
167
166
exp = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' ),
168
167
pd .NaT , Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
169
168
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 )
172
171
173
172
result = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
174
173
pd .NaT , Timestamp ('2011-01-02 10:00' ,
175
174
tz = 'US/Eastern' )], name = 'idx' )
176
175
exp = Index ([pd .NaT , Timestamp ('2011-01-01 10:00' , tz = 'Asia/Tokyo' ),
177
176
pd .NaT , Timestamp ('2011-01-02 10:00' , tz = 'US/Eastern' )],
178
177
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 )
181
180
182
181
# all NaT
183
182
result = Index ([pd .NaT , pd .NaT ], name = 'idx' )
184
183
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
188
187
189
188
# all NaT with tz
190
189
result = Index ([pd .NaT , pd .NaT ], tz = 'Asia/Tokyo' , name = 'idx' )
191
190
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
196
196
197
197
def test_construction_dti_with_mixed_timezones (self ):
198
198
# GH 11488 (not changed, added explicit tests)
0 commit comments