2727import pandas .core .common as com
2828
2929from 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
3131
3232_midnight = time (0 , 0 )
3333
@@ -255,7 +255,8 @@ def _from_sequence(cls, data, dtype=None, copy=False,
255255
256256 @classmethod
257257 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 ):
259260
260261 periods = dtl .validate_periods (periods )
261262 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,
285286 start , end , _normalized = _maybe_normalize_endpoints (start , end ,
286287 normalize )
287288
288- tz , _ = _infer_tz_from_endpoints (start , end , tz )
289+ tz = _infer_tz_from_endpoints (start , end , tz )
289290
290291 if tz is not None :
291292 # Localize the start and end arguments
@@ -295,22 +296,22 @@ def _generate_range(cls, start, end, periods, freq, tz=None,
295296 end = _maybe_localize_point (
296297 end , getattr (end , 'tz' , None ), end , freq , tz
297298 )
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- )
306299 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 )
307308 # TODO: consider re-implementing _cached_range; GH#17914
308309 index = _generate_regular_range (cls , start , end , periods , freq )
309310
310311 if tz is not None and index .tz is None :
311312 arr = conversion .tz_localize_to_utc (
312313 index .asi8 ,
313- tz , ambiguous = ambiguous )
314+ tz , ambiguous = ambiguous , nonexistent = nonexistent )
314315
315316 index = cls (arr )
316317
@@ -1878,7 +1879,6 @@ def _infer_tz_from_endpoints(start, end, tz):
18781879 Returns
18791880 -------
18801881 tz : tzinfo or None
1881- inferred_tz : tzinfo or None
18821882
18831883 Raises
18841884 ------
@@ -1901,7 +1901,7 @@ def _infer_tz_from_endpoints(start, end, tz):
19011901 elif inferred_tz is not None :
19021902 tz = inferred_tz
19031903
1904- return tz , inferred_tz
1904+ return tz
19051905
19061906
19071907def _maybe_normalize_endpoints (start , end , normalize ):
0 commit comments