Skip to content

Commit

Permalink
Bug: OverflowError in resample.agg with tz data (pandas-dev#25297)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and Pingviinituutti committed Feb 28, 2019
1 parent 8e04e37 commit 0a88ee7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Plotting
Groupby/Resample/Rolling
^^^^^^^^^^^^^^^^^^^^^^^^

-
- 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`)
-
-

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ def get_loc(self, key, method=None, tolerance=None):
except (KeyError, ValueError, TypeError):
try:
return self._get_string_slice(key)
except (TypeError, KeyError, ValueError):
except (TypeError, KeyError, ValueError, OverflowError):
pass

try:
Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/resample/test_resample_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,25 @@ def test_selection_api_validation():

exp.index.name = 'd'
assert_frame_equal(exp, df.resample('2D', level='d').sum())


@pytest.mark.parametrize('col_name', ['t2', 't2x', 't2q', 'T_2M',
't2p', 't2m', 't2m1', 'T2M'])
def test_agg_with_datetime_index_list_agg_func(col_name):
# GH 22660
# The parametrized column names would get converted to dates by our
# date parser. Some would result in OutOfBoundsError (ValueError) while
# others would result in OverflowError when passed into Timestamp.
# We catch these errors and move on to the correct branch.
df = pd.DataFrame(list(range(200)),
index=pd.date_range(start='2017-01-01', freq='15min',
periods=200, tz='Europe/Berlin'),
columns=[col_name])
result = df.resample('1d').aggregate(['mean'])
expected = pd.DataFrame([47.5, 143.5, 195.5],
index=pd.date_range(start='2017-01-01', freq='D',
periods=3, tz='Europe/Berlin'),
columns=pd.MultiIndex(levels=[[col_name],
['mean']],
codes=[[0], [0]]))
assert_frame_equal(result, expected)

0 comments on commit 0a88ee7

Please sign in to comment.