7
7
timedelta ,
8
8
)
9
9
10
- import dateutil
10
+ # import dateutil
11
+ import re
12
+
11
13
from dateutil .tz import (
12
14
gettz ,
13
15
tzoffset ,
22
24
from pandas ._libs .tslibs import timezones
23
25
from pandas ._libs .tslibs .dtypes import NpyDatetimeUnit
24
26
from pandas .errors import OutOfBoundsDatetime
25
- import pandas .util ._test_decorators as td
26
27
27
28
from pandas import (
28
29
NaT ,
29
30
Timestamp ,
30
31
)
31
32
32
- try :
33
- from zoneinfo import ZoneInfo
34
- except ImportError :
35
- ZoneInfo = None
33
+ # import pandas.util._test_decorators as td
36
34
37
35
38
36
class TestTimestampTZOperations :
@@ -67,27 +65,14 @@ def test_tz_localize_pushes_out_of_bounds(self):
67
65
def test_tz_localize_ambiguous_bool (self , unit ):
68
66
# make sure that we are correctly accepting bool values as ambiguous
69
67
# GH#14402
70
- ts = Timestamp ("2015-11-01 01:00:03" ).as_unit (unit )
68
+ ts = Timestamp ("2015-11-01 01:00:03" )._as_unit (unit )
71
69
expected0 = Timestamp ("2015-11-01 01:00:03-0500" , tz = "US/Central" )
72
70
expected1 = Timestamp ("2015-11-01 01:00:03-0600" , tz = "US/Central" )
73
71
74
72
msg = "Cannot infer dst time from 2015-11-01 01:00:03"
75
73
with pytest .raises (pytz .AmbiguousTimeError , match = msg ):
76
74
ts .tz_localize ("US/Central" )
77
75
78
- with pytest .raises (pytz .AmbiguousTimeError , match = msg ):
79
- ts .tz_localize ("dateutil/US/Central" )
80
-
81
- if ZoneInfo is not None :
82
- try :
83
- tz = ZoneInfo ("US/Central" )
84
- except KeyError :
85
- # no tzdata
86
- pass
87
- else :
88
- with pytest .raises (pytz .AmbiguousTimeError , match = msg ):
89
- ts .tz_localize (tz )
90
-
91
76
result = ts .tz_localize ("US/Central" , ambiguous = True )
92
77
assert result == expected0
93
78
assert result ._creso == getattr (NpyDatetimeUnit , f"NPY_FR_{ unit } " ).value
@@ -102,7 +87,9 @@ def test_tz_localize_ambiguous(self):
102
87
ts_no_dst = ts .tz_localize ("US/Eastern" , ambiguous = False )
103
88
104
89
assert (ts_no_dst .value - ts_dst .value ) / 1e9 == 3600
105
- msg = "Cannot infer offset with only one time"
90
+ msg = re .escape (
91
+ "ambiguous parameter must be one of: True, False, 'NaT', 'raise' (default)"
92
+ )
106
93
with pytest .raises (ValueError , match = msg ):
107
94
ts .tz_localize ("US/Eastern" , ambiguous = "infer" )
108
95
@@ -141,9 +128,9 @@ def test_tz_localize_ambiguous_raise(self):
141
128
with pytest .raises (AmbiguousTimeError , match = msg ):
142
129
ts .tz_localize ("US/Pacific" , ambiguous = "raise" )
143
130
144
- def test_tz_localize_nonexistent_invalid_arg (self , warsaw ):
131
+ def test_tz_localize_nonexistent_invalid_arg (self ):
145
132
# GH 22644
146
- tz = warsaw
133
+ tz = "Europe/Warsaw"
147
134
ts = Timestamp ("2015-03-29 02:00:00" )
148
135
msg = (
149
136
"The nonexistent argument must be one of 'raise', 'NaT', "
@@ -179,11 +166,10 @@ def test_tz_localize_ambiguous_compat(self):
179
166
# validate that pytz and dateutil are compat for dst
180
167
# when the transition happens
181
168
naive = Timestamp ("2013-10-27 01:00:00" )
182
-
183
169
pytz_zone = "Europe/London"
184
170
dateutil_zone = "dateutil/Europe/London"
185
- result_pytz = naive .tz_localize (pytz_zone , ambiguous = 0 )
186
- result_dateutil = naive .tz_localize (dateutil_zone , ambiguous = 0 )
171
+ result_pytz = naive .tz_localize (pytz_zone , ambiguous = False )
172
+ result_dateutil = naive .tz_localize (dateutil_zone , ambiguous = False )
187
173
assert result_pytz .value == result_dateutil .value
188
174
assert result_pytz .value == 1382835600000000000
189
175
@@ -194,8 +180,8 @@ def test_tz_localize_ambiguous_compat(self):
194
180
assert str (result_pytz ) == str (result_dateutil )
195
181
196
182
# 1 hour difference
197
- result_pytz = naive .tz_localize (pytz_zone , ambiguous = 1 )
198
- result_dateutil = naive .tz_localize (dateutil_zone , ambiguous = 1 )
183
+ result_pytz = naive .tz_localize (pytz_zone , ambiguous = True )
184
+ result_dateutil = naive .tz_localize (dateutil_zone , ambiguous = True )
199
185
assert result_pytz .value == result_dateutil .value
200
186
assert result_pytz .value == 1382832000000000000
201
187
@@ -275,7 +261,7 @@ def test_timestamp_tz_localize_nonexistent_shift(
275
261
tz = tz_type + tz
276
262
if isinstance (shift , str ):
277
263
shift = "shift_" + shift
278
- ts = Timestamp (start_ts ).as_unit (unit )
264
+ ts = Timestamp (start_ts )._as_unit (unit )
279
265
result = ts .tz_localize (tz , nonexistent = shift )
280
266
expected = Timestamp (end_ts ).tz_localize (tz )
281
267
@@ -291,27 +277,28 @@ def test_timestamp_tz_localize_nonexistent_shift(
291
277
assert result ._creso == getattr (NpyDatetimeUnit , f"NPY_FR_{ unit } " ).value
292
278
293
279
@pytest .mark .parametrize ("offset" , [- 1 , 1 ])
294
- def test_timestamp_tz_localize_nonexistent_shift_invalid (self , offset , warsaw ):
280
+ @pytest .mark .parametrize ("tz_type" , ["" , "dateutil/" ])
281
+ def test_timestamp_tz_localize_nonexistent_shift_invalid (self , offset , tz_type ):
295
282
# GH 8917, 24466
296
- tz = warsaw
283
+ tz = tz_type + "Europe/Warsaw"
297
284
ts = Timestamp ("2015-03-29 02:20:00" )
298
285
msg = "The provided timedelta will relocalize on a nonexistent time"
299
286
with pytest .raises (ValueError , match = msg ):
300
287
ts .tz_localize (tz , nonexistent = timedelta (seconds = offset ))
301
288
289
+ @pytest .mark .parametrize ("tz" , ["Europe/Warsaw" , "dateutil/Europe/Warsaw" ])
302
290
@pytest .mark .parametrize ("unit" , ["ns" , "us" , "ms" , "s" ])
303
- def test_timestamp_tz_localize_nonexistent_NaT (self , warsaw , unit ):
291
+ def test_timestamp_tz_localize_nonexistent_NaT (self , tz , unit ):
304
292
# GH 8917
305
- tz = warsaw
306
- ts = Timestamp ("2015-03-29 02:20:00" ).as_unit (unit )
293
+ ts = Timestamp ("2015-03-29 02:20:00" )._as_unit (unit )
307
294
result = ts .tz_localize (tz , nonexistent = "NaT" )
308
295
assert result is NaT
309
296
297
+ @pytest .mark .parametrize ("tz" , ["Europe/Warsaw" , "dateutil/Europe/Warsaw" ])
310
298
@pytest .mark .parametrize ("unit" , ["ns" , "us" , "ms" , "s" ])
311
- def test_timestamp_tz_localize_nonexistent_raise (self , warsaw , unit ):
299
+ def test_timestamp_tz_localize_nonexistent_raise (self , tz , unit ):
312
300
# GH 8917
313
- tz = warsaw
314
- ts = Timestamp ("2015-03-29 02:20:00" ).as_unit (unit )
301
+ ts = Timestamp ("2015-03-29 02:20:00" )._as_unit (unit )
315
302
msg = "2015-03-29 02:20:00"
316
303
with pytest .raises (pytz .NonExistentTimeError , match = msg ):
317
304
ts .tz_localize (tz , nonexistent = "raise" )
@@ -355,18 +342,18 @@ def test_astimezone(self, tzstr):
355
342
assert expected == result
356
343
assert isinstance (result , Timestamp )
357
344
358
- @td .skip_if_windows
359
- def test_tz_convert_utc_with_system_utc (self ):
345
+ # @td.skip_if_windows
346
+ # def test_tz_convert_utc_with_system_utc(self):
360
347
361
- # from system utc to real utc
362
- ts = Timestamp ("2001-01-05 11:56" , tz = timezones .maybe_get_tz ("dateutil/UTC" ))
363
- # check that the time hasn't changed.
364
- assert ts == ts .tz_convert (dateutil .tz .tzutc ())
348
+ # # from system utc to real utc
349
+ # ts = Timestamp("2001-01-05 11:56", tz=timezones.maybe_get_tz("dateutil/UTC"))
350
+ # # check that the time hasn't changed.
351
+ # assert ts == ts.tz_convert(dateutil.tz.tzutc())
365
352
366
- # from system utc to real utc
367
- ts = Timestamp ("2001-01-05 11:56" , tz = timezones .maybe_get_tz ("dateutil/UTC" ))
368
- # check that the time hasn't changed.
369
- assert ts == ts .tz_convert (dateutil .tz .tzutc ())
353
+ # # from system utc to real utc
354
+ # ts = Timestamp("2001-01-05 11:56", tz=timezones.maybe_get_tz("dateutil/UTC"))
355
+ # # check that the time hasn't changed.
356
+ # assert ts == ts.tz_convert(dateutil.tz.tzutc())
370
357
371
358
# ------------------------------------------------------------------
372
359
# Timestamp.__init__ with tz str or tzinfo
0 commit comments