Skip to content

Commit 99a5367

Browse files
committed
Fix unittest error and lint warning
1 parent 940fb22 commit 99a5367

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

pandas/tseries/resample.py

100644100755
+9-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pandas as pd
77
from pandas.core.base import AbstractMethodError, GroupByMixin
8+
from pandas.core.config_init import pc_ambiguous_as_wide_doc
89

910
from pandas.core.groupby import (BinGrouper, Grouper, _GroupBy, GroupBy,
1011
SeriesGroupBy, groupby, PanelGroupBy)
@@ -1285,6 +1286,12 @@ def _adjust_dates_anchored(first, last, offset, closed='right', base=0):
12851286

12861287
first_tzinfo = first.tzinfo
12871288
last_tzinfo = last.tzinfo
1289+
first_dst = bool(first.dst())
1290+
last_dst = bool(last.dst())
1291+
1292+
first = first.tz_localize(None)
1293+
last = last.tz_localize(None)
1294+
12881295
start_day_nanos = first.normalize().value
12891296

12901297
base_nanos = (base % offset.n) * offset.nanos // offset.n
@@ -1319,9 +1326,8 @@ def _adjust_dates_anchored(first, last, offset, closed='right', base=0):
13191326
else:
13201327
lresult = last.value + offset.nanos
13211328

1322-
return (Timestamp(fresult, tz=first_tzinfo),
1323-
Timestamp(lresult, tz=last_tzinfo))
1324-
1329+
return (Timestamp(fresult).tz_localize(first_tzinfo, ambiguous=first_dst),
1330+
Timestamp(lresult).tz_localize(last_tzinfo, ambiguous=last_dst))
13251331

13261332

13271333
def asfreq(obj, freq, method=None, how=None, normalize=False):

pandas/tseries/tests/test_resample.py

100644100755
+12-1
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,18 @@ def test_resample_size(self):
19121912
right = Series(val, index=ix)
19131913
assert_series_equal(left, right)
19141914

1915-
def test_resmaple_dst_anchor(self):
1915+
def test_resample_across_dst(self):
1916+
#14682
1917+
df1 = DataFrame([1477786980, 1477790580], columns=['ts'])
1918+
df2 = DataFrame([1477785600, 1477789200], columns=['ts'])
1919+
dti1 = DatetimeIndex(pd.to_datetime(df1.ts, unit='s').dt.tz_localize('UTC').dt.tz_convert('Europe/Madrid'))
1920+
dti2 = DatetimeIndex(pd.to_datetime(df2.ts, unit='s').dt.tz_localize('UTC').dt.tz_convert('Europe/Madrid'))
1921+
df = DataFrame([5, 5], index=dti1)
1922+
assert_frame_equal(
1923+
df.resample(rule='H').sum(),
1924+
DataFrame([5, 5], index=dti2))
1925+
1926+
def test_resample_dst_anchor(self):
19161927
# 5172
19171928
dti = DatetimeIndex([datetime(2012, 11, 4, 23)], tz='US/Eastern')
19181929
df = DataFrame([5], index=dti)

0 commit comments

Comments
 (0)