27
27
import pandas .core .common as com
28
28
29
29
from pandas .tseries .frequencies import get_period_alias , to_offset
30
- from pandas .tseries .offsets import Tick , generate_range
30
+ from pandas .tseries .offsets import Day , Tick , generate_range
31
31
32
32
_midnight = time (0 , 0 )
33
33
@@ -255,7 +255,8 @@ def _from_sequence(cls, data, dtype=None, copy=False,
255
255
256
256
@classmethod
257
257
def _generate_range (cls , start , end , periods , freq , tz = None ,
258
- normalize = False , ambiguous = 'raise' , closed = None ):
258
+ normalize = False , ambiguous = 'raise' ,
259
+ nonexistent = 'raise' , closed = None ):
259
260
260
261
periods = dtl .validate_periods (periods )
261
262
if freq is None and any (x is None for x in [periods , start , end ]):
@@ -285,7 +286,7 @@ def _generate_range(cls, start, end, periods, freq, tz=None,
285
286
start , end , _normalized = _maybe_normalize_endpoints (start , end ,
286
287
normalize )
287
288
288
- tz , _ = _infer_tz_from_endpoints (start , end , tz )
289
+ tz = _infer_tz_from_endpoints (start , end , tz )
289
290
290
291
if tz is not None :
291
292
# Localize the start and end arguments
@@ -295,22 +296,22 @@ def _generate_range(cls, start, end, periods, freq, tz=None,
295
296
end = _maybe_localize_point (
296
297
end , getattr (end , 'tz' , None ), end , freq , tz
297
298
)
298
- if start and end :
299
- # Make sure start and end have the same tz
300
- start = _maybe_localize_point (
301
- start , start .tz , end .tz , freq , tz
302
- )
303
- end = _maybe_localize_point (
304
- end , end .tz , start .tz , freq , tz
305
- )
306
299
if freq is not None :
300
+ # We break Day arithmetic (fixed 24 hour) here and opt for
301
+ # Day to mean calendar day (23/24/25 hour). Therefore, strip
302
+ # tz info from start and day to avoid DST arithmetic
303
+ if isinstance (freq , Day ):
304
+ if start is not None :
305
+ start = start .tz_localize (None )
306
+ if end is not None :
307
+ end = end .tz_localize (None )
307
308
# TODO: consider re-implementing _cached_range; GH#17914
308
309
index = _generate_regular_range (cls , start , end , periods , freq )
309
310
310
311
if tz is not None and index .tz is None :
311
312
arr = conversion .tz_localize_to_utc (
312
313
index .asi8 ,
313
- tz , ambiguous = ambiguous )
314
+ tz , ambiguous = ambiguous , nonexistent = nonexistent )
314
315
315
316
index = cls (arr )
316
317
@@ -1878,7 +1879,6 @@ def _infer_tz_from_endpoints(start, end, tz):
1878
1879
Returns
1879
1880
-------
1880
1881
tz : tzinfo or None
1881
- inferred_tz : tzinfo or None
1882
1882
1883
1883
Raises
1884
1884
------
@@ -1901,7 +1901,7 @@ def _infer_tz_from_endpoints(start, end, tz):
1901
1901
elif inferred_tz is not None :
1902
1902
tz = inferred_tz
1903
1903
1904
- return tz , inferred_tz
1904
+ return tz
1905
1905
1906
1906
1907
1907
def _maybe_normalize_endpoints (start , end , normalize ):
0 commit comments