@@ -147,6 +147,7 @@ def __new__(cls, data=None,
147
147
148
148
dayfirst = kwds .pop ('dayfirst' , None )
149
149
yearfirst = kwds .pop ('yearfirst' , None )
150
+ infer_dst = kwds .pop ('infer_dst' , False )
150
151
warn = False
151
152
if 'offset' in kwds and kwds ['offset' ]:
152
153
freq = kwds ['offset' ]
@@ -183,7 +184,8 @@ def __new__(cls, data=None,
183
184
184
185
if data is None :
185
186
return cls ._generate (start , end , periods , name , offset ,
186
- tz = tz , normalize = normalize )
187
+ tz = tz , normalize = normalize ,
188
+ infer_dst = infer_dst )
187
189
188
190
if not isinstance (data , np .ndarray ):
189
191
if np .isscalar (data ):
@@ -209,7 +211,7 @@ def __new__(cls, data=None,
209
211
data .name = name
210
212
211
213
if tz is not None :
212
- return data .tz_localize (tz )
214
+ return data .tz_localize (tz , infer_dst = infer_dst )
213
215
214
216
return data
215
217
@@ -261,7 +263,8 @@ def __new__(cls, data=None,
261
263
getattr (data , 'tz' , None ) is None ):
262
264
# Convert tz-naive to UTC
263
265
ints = subarr .view ('i8' )
264
- subarr = tslib .tz_localize_to_utc (ints , tz )
266
+ subarr = tslib .tz_localize_to_utc (ints , tz ,
267
+ infer_dst = infer_dst )
265
268
266
269
subarr = subarr .view (_NS_DTYPE )
267
270
@@ -286,7 +289,7 @@ def __new__(cls, data=None,
286
289
287
290
@classmethod
288
291
def _generate (cls , start , end , periods , name , offset ,
289
- tz = None , normalize = False ):
292
+ tz = None , normalize = False , infer_dst = False ):
290
293
if com ._count_not_none (start , end , periods ) != 2 :
291
294
raise ValueError ('Must specify two of start, end, or periods' )
292
295
@@ -375,7 +378,8 @@ def _generate(cls, start, end, periods, name, offset,
375
378
index = _generate_regular_range (start , end , periods , offset )
376
379
377
380
if tz is not None and getattr (index , 'tz' , None ) is None :
378
- index = tslib .tz_localize_to_utc (com ._ensure_int64 (index ), tz )
381
+ index = tslib .tz_localize_to_utc (com ._ensure_int64 (index ), tz ,
382
+ infer_dst = infer_dst )
379
383
index = index .view (_NS_DTYPE )
380
384
381
385
index = index .view (cls )
@@ -1537,9 +1541,17 @@ def tz_convert(self, tz):
1537
1541
# No conversion since timestamps are all UTC to begin with
1538
1542
return self ._simple_new (self .values , self .name , self .offset , tz )
1539
1543
1540
- def tz_localize (self , tz ):
1544
+ def tz_localize (self , tz , infer_dst = False ):
1541
1545
"""
1542
1546
Localize tz-naive DatetimeIndex to given time zone (using pytz)
1547
+
1548
+ Parameters
1549
+ ----------
1550
+ tz : string or pytz.timezone
1551
+ Time zone for time. Corresponding timestamps would be converted to
1552
+ time zone of the TimeSeries
1553
+ infer_dst : boolean, default False
1554
+ Attempt to infer fall dst-transition hours based on order
1543
1555
1544
1556
Returns
1545
1557
-------
@@ -1550,7 +1562,7 @@ def tz_localize(self, tz):
1550
1562
tz = tools ._maybe_get_tz (tz )
1551
1563
1552
1564
# Convert to UTC
1553
- new_dates = tslib .tz_localize_to_utc (self .asi8 , tz )
1565
+ new_dates = tslib .tz_localize_to_utc (self .asi8 , tz , infer_dst = infer_dst )
1554
1566
new_dates = new_dates .view (_NS_DTYPE )
1555
1567
1556
1568
return self ._simple_new (new_dates , self .name , self .offset , tz )
0 commit comments