From 8a790bedd54ec0becadbe7672bf9130966a35a8f Mon Sep 17 00:00:00 2001 From: Younggun Kim Date: Tue, 5 May 2015 06:10:40 +0900 Subject: [PATCH] ENH: Series.resample performance with datetime64[ns] #7754 --- doc/source/whatsnew/v0.17.0.txt | 2 ++ pandas/core/groupby.py | 2 ++ vb_suite/timeseries.py | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index 9bf478831ea01..102460ff6d476 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -53,6 +53,8 @@ Removal of prior version deprecations/changes Performance Improvements ~~~~~~~~~~~~~~~~~~~~~~~~ +- Improved ``Series.resample`` performance with dtype=datetime64[ns] (:issue:`7754`) + .. _whatsnew_0170.bug_fixes: Bug Fixes diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 1f76d80c34a90..8b8e5e4c2fe02 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -1496,6 +1496,8 @@ def aggregate(self, values, how, axis=0): if is_datetime_or_timedelta_dtype(values.dtype): values = values.view('int64') + # GH 7754 + is_numeric = True elif is_bool_dtype(values.dtype): values = _algos.ensure_float64(values) elif com.is_integer_dtype(values): diff --git a/vb_suite/timeseries.py b/vb_suite/timeseries.py index f0c3961ae0277..57fb1ada78691 100644 --- a/vb_suite/timeseries.py +++ b/vb_suite/timeseries.py @@ -135,6 +135,16 @@ def date_range(start=None, end=None, periods=None, freq=None): Benchmark("ts.resample('D', how='mean')", setup, start_date=datetime(2012, 4, 25)) +# GH 7754 +setup = common_setup + """ +rng = date_range(start='2000-01-01 00:00:00', + end='2000-01-01 10:00:00', freq='555000U') +int_ts = Series(5, rng, dtype='int64') +ts = int_ts.astype('datetime64[ns]') +""" + +timeseries_resample_datetime64 = Benchmark("ts.resample('1S', how='last')", setup) + #---------------------------------------------------------------------- # to_datetime