Skip to content

BUG: OverflowError in resample.agg with tz data #25297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)