Skip to content

Commit ea9848c

Browse files
mroeschkejreback
authored andcommitted
Bug: OverflowError in resample.agg with tz data (#25297)
1 parent 33b11b9 commit ea9848c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Plotting
172172
Groupby/Resample/Rolling
173173
^^^^^^^^^^^^^^^^^^^^^^^^
174174

175-
-
175+
- Bug in :meth:`pandas.core.resample.Resampler.agg` with a timezone aware index where ``OverflowError`` would raise when passing a list of functions (:issue:`22660`)
176176
-
177177
-
178178

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ def get_loc(self, key, method=None, tolerance=None):
10101010
except (KeyError, ValueError, TypeError):
10111011
try:
10121012
return self._get_string_slice(key)
1013-
except (TypeError, KeyError, ValueError):
1013+
except (TypeError, KeyError, ValueError, OverflowError):
10141014
pass
10151015

10161016
try:

pandas/tests/resample/test_resample_api.py

+22
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,25 @@ def test_selection_api_validation():
549549

550550
exp.index.name = 'd'
551551
assert_frame_equal(exp, df.resample('2D', level='d').sum())
552+
553+
554+
@pytest.mark.parametrize('col_name', ['t2', 't2x', 't2q', 'T_2M',
555+
't2p', 't2m', 't2m1', 'T2M'])
556+
def test_agg_with_datetime_index_list_agg_func(col_name):
557+
# GH 22660
558+
# The parametrized column names would get converted to dates by our
559+
# date parser. Some would result in OutOfBoundsError (ValueError) while
560+
# others would result in OverflowError when passed into Timestamp.
561+
# We catch these errors and move on to the correct branch.
562+
df = pd.DataFrame(list(range(200)),
563+
index=pd.date_range(start='2017-01-01', freq='15min',
564+
periods=200, tz='Europe/Berlin'),
565+
columns=[col_name])
566+
result = df.resample('1d').aggregate(['mean'])
567+
expected = pd.DataFrame([47.5, 143.5, 195.5],
568+
index=pd.date_range(start='2017-01-01', freq='D',
569+
periods=3, tz='Europe/Berlin'),
570+
columns=pd.MultiIndex(levels=[[col_name],
571+
['mean']],
572+
codes=[[0], [0]]))
573+
assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)