@@ -184,7 +184,9 @@ def test_to_datetime_format_weeks(self, cache):
184
184
for s , format , dt in data :
185
185
assert to_datetime (s , format = format , cache = cache ) == dt
186
186
187
- @pytest .skipif (not PY3 , reason = "datetime.timezone not supported in PY2" )
187
+ @pytest .mark .skipif (not PY3 ,
188
+ reason = "datetime.timezone not supported in PY2" )
189
+ @pytest .mark .xfail (reason = "GH #20257" )
188
190
def test_to_datetime_parse_timezone (self ):
189
191
from datetime import timezone
190
192
# %Z parsing only
@@ -195,6 +197,17 @@ def test_to_datetime_parse_timezone(self):
195
197
expected = pd .DatetimeIndex (expected_dates )
196
198
tm .assert_index_equal (result , expected )
197
199
200
+ result = pd .to_datetime (dates , format = fmt , box = False )
201
+ expected = np .array (expected_dates , dtype = object )
202
+ tm .assert_numpy_array_equal (result , expected )
203
+
204
+ dates = ['2010-01-01 12:00:00 UTC' , '2010-01-01 12:00:00 GMT' ]
205
+ result = pd .to_datetime (dates , format = fmt )
206
+ expected_dates = [pd .Timestamp ('2010-01-01 12:00:00' , tz = 'UTC' ),
207
+ pd .Timestamp ('2010-01-01 12:00:00' , tz = 'GMT' )]
208
+ expected = np .array (expected_dates , dtype = object )
209
+ tm .assert_numpy_array_equal (result , expected )
210
+
198
211
# %z parsing only
199
212
dates = ['2010-01-01 12:00:00 +0100' ] * 2
200
213
fmt = '%Y-%m-%d %H:%M:%S %z'
@@ -204,17 +217,31 @@ def test_to_datetime_parse_timezone(self):
204
217
expected = pd .DatetimeIndex (expected_dates )
205
218
tm .assert_index_equal (result , expected )
206
219
220
+ result = pd .to_datetime (dates , format = fmt , box = False )
221
+ expected = np .array (expected_dates , dtype = object )
222
+ tm .assert_numpy_array_equal (result , expected )
223
+
224
+ dates = ['2010-01-01 12:00:00 +0100' , '2010-01-01 12:00:00 -0100' ]
225
+ result = pd .to_datetime (dates , format = fmt )
226
+ expected_dates = [pd .Timestamp ('2010-01-01 12:00:00' ,
227
+ tzinfo = pytz .FixedOffset (60 )),
228
+ pd .Timestamp ('2010-01-01 12:00:00' ,
229
+ tzinfo = pytz .FixedOffset (- 60 ))]
230
+ expected = np .array (expected_dates , dtype = object )
231
+ tm .assert_numpy_array_equal (result , expected )
232
+
207
233
# %z and %Z parsing
208
234
dates = ['2010-01-01 12:00:00 UTC +0100' ] * 2
209
235
fmt = '%Y-%m-%d %H:%M:%S %Z %z'
210
236
result = pd .to_datetime (dates , format = fmt )
211
237
tzinfo = timezone (timedelta (minutes = 60 ), 'UTC' )
212
- expected_dates = [pd .Timestamp ('2010-01-01 12 :00:00' , tzinfo = tzinfo )]
238
+ expected_dates = [pd .Timestamp ('2010-01-01 13 :00:00' , tzinfo = tzinfo )]
213
239
expected = np .array (expected_dates * 2 , dtype = object )
214
240
tm .assert_numpy_array_equal (result , expected )
215
241
216
242
with pytest .raises (ValueError ):
217
- pd .to_datetime (dates , format = fmt , tz = 'US/Pacific' )
243
+ pd .to_datetime (dates , format = fmt , utc = True )
244
+
218
245
219
246
class TestToDatetime (object ):
220
247
def test_to_datetime_pydatetime (self ):
0 commit comments