@@ -1666,10 +1666,11 @@ def _get_timestamp_range_edges(
1666
1666
The dateoffset to which the Timestamps will be adjusted.
1667
1667
closed : {'right', 'left'}, default None
1668
1668
Which side of bin interval is closed.
1669
- origin : {'epoch', 'start', 'start_day'}, Timestamp or str , default 'start_day'
1670
- The timestamp on which to adjust the grouping. It must be timezone aware if
1671
- the index of the resampled data is .
1669
+ origin : {'epoch', 'start', 'start_day'} or Timestamp , default 'start_day'
1670
+ The timestamp on which to adjust the grouping. The timezone of origin must
1671
+ match the timezone of the index .
1672
1672
If a timestamp is not used, these values are also supported:
1673
+
1673
1674
- 'epoch': `origin` is 1970-01-01
1674
1675
- 'start': `origin` is the first value of the timeseries
1675
1676
- 'start_day': `origin` is the first day at midnight of the timeseries
@@ -1680,38 +1681,34 @@ def _get_timestamp_range_edges(
1680
1681
-------
1681
1682
A tuple of length 2, containing the adjusted pd.Timestamp objects.
1682
1683
"""
1683
- if isinstance (freq , Tick ):
1684
- if origin not in {"epoch" , "start" , "start_day" }:
1685
- is_idx_tz_aware = first .tz is not None or last .tz is not None
1686
- if origin .tz is None and is_idx_tz_aware :
1687
- raise ValueError ("The origin must have the same timezone as the index." )
1684
+ index_tz = first .tz
1685
+ if isinstance (origin , Timestamp ) and (origin .tz is None ) != (index_tz is None ):
1686
+ raise ValueError ("The origin must have the same timezone as the index." )
1688
1687
1688
+ if isinstance (freq , Tick ):
1689
1689
if isinstance (freq , Day ):
1690
1690
# _adjust_dates_anchored assumes 'D' means 24H, but first/last
1691
1691
# might contain a DST transition (23H, 24H, or 25H).
1692
1692
# So "pretend" the dates are naive when adjusting the endpoints
1693
- tz = first .tz
1694
1693
first = first .tz_localize (None )
1695
1694
last = last .tz_localize (None )
1696
1695
1697
1696
first , last = _adjust_dates_anchored (
1698
1697
first , last , freq , closed = closed , origin = origin , offset = offset ,
1699
1698
)
1700
1699
if isinstance (freq , Day ):
1701
- first = first .tz_localize (tz )
1702
- last = last .tz_localize (tz )
1703
- return first , last
1704
-
1700
+ first = first .tz_localize (index_tz )
1701
+ last = last .tz_localize (index_tz )
1705
1702
else :
1706
1703
first = first .normalize ()
1707
1704
last = last .normalize ()
1708
1705
1709
- if closed == "left" :
1710
- first = Timestamp (freq .rollback (first ))
1711
- else :
1712
- first = Timestamp (first - freq )
1706
+ if closed == "left" :
1707
+ first = Timestamp (freq .rollback (first ))
1708
+ else :
1709
+ first = Timestamp (first - freq )
1713
1710
1714
- last = Timestamp (last + freq )
1711
+ last = Timestamp (last + freq )
1715
1712
1716
1713
return first , last
1717
1714
@@ -1733,14 +1730,15 @@ def _get_period_range_edges(
1733
1730
The freq to which the Periods will be adjusted.
1734
1731
closed : {'right', 'left'}, default None
1735
1732
Which side of bin interval is closed.
1736
- origin : {'epoch', 'start', 'start_day'}, Timestamp or str , default 'start_day'
1737
- The timestamp on which to adjust the grouping. It must be timezone aware if
1738
- the index of the resampled data is .
1733
+ origin : {'epoch', 'start', 'start_day'}, Timestamp, default 'start_day'
1734
+ The timestamp on which to adjust the grouping. The timezone of origin must
1735
+ match the timezone of the index .
1739
1736
1740
1737
If a timestamp is not used, these values are also supported:
1741
- - If 'epoch': `origin` is 1970-01-01
1742
- - If 'start': then `origin` is the first value of the timeseries
1743
- - If 'start_day', then `origin` is the first day at midnight of the timeseries
1738
+
1739
+ - 'epoch': `origin` is 1970-01-01
1740
+ - 'start': `origin` is the first value of the timeseries
1741
+ - 'start_day': `origin` is the first day at midnight of the timeseries
1744
1742
offset : pd.Timedelta, default is None
1745
1743
An offset timedelta added to the origin.
1746
1744
0 commit comments