From 57d16e5feac25264c487f82f448f6c1da1b1b25e Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 24 Dec 2017 00:19:56 -0800 Subject: [PATCH 1/3] CLN: ASV offset --- asv_bench/benchmarks/offset.py | 266 ++++++++------------------------- 1 file changed, 65 insertions(+), 201 deletions(-) diff --git a/asv_bench/benchmarks/offset.py b/asv_bench/benchmarks/offset.py index 849776bf9a591..2104962694b76 100644 --- a/asv_bench/benchmarks/offset.py +++ b/asv_bench/benchmarks/offset.py @@ -2,51 +2,58 @@ from datetime import datetime import numpy as np - import pandas as pd -from pandas import date_range - try: - import pandas.tseries.holiday + import pandas.tseries.holiday # noqa except ImportError: pass hcal = pd.tseries.holiday.USFederalHolidayCalendar() +# These offests currently raise a NotImplimentedError with .apply_index() +non_apply = [pd.offsets.Day(), + pd.offsets.BYearEnd(), + pd.offsets.BYearBegin(), + pd.offsets.BQuarterEnd(), + pd.offsets.BQuarterBegin(), + pd.offsets.BMonthEnd(), + pd.offsets.BMonthBegin(), + pd.offsets.CustomBusinessDay(), + pd.offsets.CustomBusinessDay(calendar=hcal), + pd.offsets.CustomBusinessMonthBegin(calendar=hcal), + pd.offsets.CustomBusinessMonthEnd(calendar=hcal), + pd.offsets.CustomBusinessMonthEnd(calendar=hcal)] +other_offsets = [pd.offsets.YearEnd(), pd.offsets.YearBegin(), + pd.offsets.QuarterEnd(), pd.offsets.QuarterBegin(), + pd.offsets.MonthEnd(), pd.offsets.MonthBegin(), + pd.offsets.DateOffset(months=2, days=2), + pd.offsets.BusinessDay(), pd.offsets.SemiMonthEnd(), + pd.offsets.SemiMonthBegin()] +offsets = non_apply + other_offsets class ApplyIndex(object): - goal_time = 0.2 - params = [pd.offsets.YearEnd(), pd.offsets.YearBegin(), - pd.offsets.BYearEnd(), pd.offsets.BYearBegin(), - pd.offsets.QuarterEnd(), pd.offsets.QuarterBegin(), - pd.offsets.BQuarterEnd(), pd.offsets.BQuarterBegin(), - pd.offsets.MonthEnd(), pd.offsets.MonthBegin(), - pd.offsets.BMonthEnd(), pd.offsets.BMonthBegin()] - - def setup(self, param): - self.offset = param + goal_time = 0.2 - self.N = 100000 - self.rng = date_range(start='1/1/2000', periods=self.N, freq='T') - self.ser = pd.Series(self.rng) + params = other_offsets + param_names = ['offset'] - def time_apply_index(self, param): - self.rng + self.offset + def setup(self, offset): + N = 10000 + self.rng = pd.date_range(start='1/1/2000', periods=N, freq='T') - def time_apply_series(self, param): - self.ser + self.offset + def time_apply_index(self, offset): + offset.apply_index(self.rng) class OnOffset(object): + goal_time = 0.2 - params = [pd.offsets.QuarterBegin(), pd.offsets.QuarterEnd(), - pd.offsets.BQuarterBegin(), pd.offsets.BQuarterEnd()] + params = offsets param_names = ['offset'] def setup(self, offset): - self.offset = offset self.dates = [datetime(2016, m, d) for m in [10, 11, 12] for d in [1, 2, 3, 28, 29, 30, 31] @@ -54,205 +61,62 @@ def setup(self, offset): def time_on_offset(self, offset): for date in self.dates: - self.offset.onOffset(date) - - -class DatetimeIndexArithmetic(object): - goal_time = 0.2 - - def setup(self): - self.N = 100000 - self.rng = date_range(start='1/1/2000', periods=self.N, freq='T') - self.day_offset = pd.offsets.Day() - self.relativedelta_offset = pd.offsets.DateOffset(months=2, days=2) - self.busday_offset = pd.offsets.BusinessDay() - - def time_add_offset_delta(self): - self.rng + self.day_offset - - def time_add_offset_fast(self): - self.rng + self.relativedelta_offset - - def time_add_offset_slow(self): - self.rng + self.busday_offset - - -class SeriesArithmetic(object): - goal_time = 0.2 + offset.onOffset(date) - def setup(self): - self.N = 100000 - rng = date_range(start='20140101', freq='T', periods=self.N) - self.ser = pd.Series(rng) - self.day_offset = pd.offsets.Day() - self.relativedelta_offset = pd.offsets.DateOffset(months=2, days=2) - self.busday_offset = pd.offsets.BusinessDay() - def time_add_offset_delta(self): - self.ser + self.day_offset +class OffsetSeriesArithmetic(object): - def time_add_offset_fast(self): - self.ser + self.relativedelta_offset - - def time_add_offset_slow(self): - self.ser + self.busday_offset - - -class YearBegin(object): goal_time = 0.2 + params = offsets + param_names = ['offset'] - def setup(self): - self.date = datetime(2011, 1, 1) - self.year = pd.offsets.YearBegin() + def setup(self, offset): + N = 10000 + rng = pd.date_range(start='1/1/2000', periods=N, freq='T') + self.data = pd.Series(rng) - def time_timeseries_year_apply(self): - self.year.apply(self.date) + def time_add_offset(self, offset): + self.data + offset - def time_timeseries_year_incr(self): - self.date + self.year +class OffsetDatetimeIndexArithmetic(object): -class Day(object): goal_time = 0.2 + params = offsets + param_names = ['offset'] - def setup(self): - self.date = datetime(2011, 1, 1) - self.day = pd.offsets.Day() + def setup(self, offset): + N = 10000 + self.data = pd.date_range(start='1/1/2000', periods=N, freq='T') - def time_timeseries_day_apply(self): - self.day.apply(self.date) + def time_add_offset(self, offset): + self.data + offset - def time_timeseries_day_incr(self): - self.date + self.day +class OffestDatetimeArithmetic(object): -class CBDay(object): goal_time = 0.2 + params = offsets + param_names = ['offset'] - def setup(self): + def setup(self, offset): self.date = datetime(2011, 1, 1) self.dt64 = np.datetime64('2011-01-01 09:00Z') - self.cday = pd.offsets.CustomBusinessDay() - - def time_custom_bday_decr(self): - self.date - self.cday - - def time_custom_bday_incr(self): - self.date + self.cday - - def time_custom_bday_apply(self): - self.cday.apply(self.date) - - def time_custom_bday_apply_dt64(self): - self.cday.apply(self.dt64) - - -class CBDayHolidays(object): - goal_time = 0.2 - - def setup(self): - self.date = datetime(2011, 1, 1) - self.cdayh = pd.offsets.CustomBusinessDay(calendar=hcal) - - def time_custom_bday_cal_incr(self): - self.date + 1 * self.cdayh - - def time_custom_bday_cal_decr(self): - self.date - 1 * self.cdayh - - def time_custom_bday_cal_incr_n(self): - self.date + 10 * self.cdayh - - def time_custom_bday_cal_incr_neg_n(self): - self.date - 10 * self.cdayh - - -class CBMonthBegin(object): - goal_time = 0.2 - - def setup(self): - self.date = datetime(2011, 1, 1) - self.cmb = pd.offsets.CustomBusinessMonthBegin(calendar=hcal) - - def time_custom_bmonthbegin_decr_n(self): - self.date - (10 * self.cmb) - - def time_custom_bmonthbegin_incr_n(self): - self.date + (10 * self.cmb) - - -class CBMonthEnd(object): - goal_time = 0.2 - - def setup(self): - self.date = datetime(2011, 1, 1) - self.cme = pd.offsets.CustomBusinessMonthEnd(calendar=hcal) - - def time_custom_bmonthend_incr(self): - self.date + self.cme - - def time_custom_bmonthend_incr_n(self): - self.date + (10 * self.cme) - - def time_custom_bmonthend_decr_n(self): - self.date - (10 * self.cme) - - -class SemiMonthOffset(object): - goal_time = 0.2 - - def setup(self): - self.N = 100000 - self.rng = date_range(start='1/1/2000', periods=self.N, freq='T') - # date is not on an offset which will be slowest case - self.date = datetime(2011, 1, 2) - self.semi_month_end = pd.offsets.SemiMonthEnd() - self.semi_month_begin = pd.offsets.SemiMonthBegin() - - def time_end_apply(self): - self.semi_month_end.apply(self.date) - - def time_end_incr(self): - self.date + self.semi_month_end - - def time_end_incr_n(self): - self.date + 10 * self.semi_month_end - - def time_end_decr(self): - self.date - self.semi_month_end - - def time_end_decr_n(self): - self.date - 10 * self.semi_month_end - - def time_end_apply_index(self): - self.semi_month_end.apply_index(self.rng) - - def time_end_incr_rng(self): - self.rng + self.semi_month_end - - def time_end_decr_rng(self): - self.rng - self.semi_month_end - - def time_begin_apply(self): - self.semi_month_begin.apply(self.date) - - def time_begin_incr(self): - self.date + self.semi_month_begin - def time_begin_incr_n(self): - self.date + 10 * self.semi_month_begin + def time_apply(self, offset): + offset.apply(self.date) - def time_begin_decr(self): - self.date - self.semi_month_begin + def time_apply_np_dt64(self, offset): + offset.apply(self.dt64) - def time_begin_decr_n(self): - self.date - 10 * self.semi_month_begin + def time_add(self, offset): + self.date + offset - def time_begin_apply_index(self): - self.semi_month_begin.apply_index(self.rng) + def time_add_10(self, offset): + self.date + (10 * offset) - def time_begin_incr_rng(self): - self.rng + self.semi_month_begin + def time_subtract(self, offset): + self.date - offset - def time_begin_decr_rng(self): - self.rng - self.semi_month_begin + def time_subtract_10(self, offset): + self.date - (10 * offset) From e97e7c017313873dff698205b28a80b9875fc009 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sat, 30 Dec 2017 21:29:01 -0800 Subject: [PATCH 2/3] Reduce samples for addition --- asv_bench/benchmarks/offset.py | 4 ++-- ci/lint.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/asv_bench/benchmarks/offset.py b/asv_bench/benchmarks/offset.py index 2104962694b76..034e861e7fc01 100644 --- a/asv_bench/benchmarks/offset.py +++ b/asv_bench/benchmarks/offset.py @@ -71,7 +71,7 @@ class OffsetSeriesArithmetic(object): param_names = ['offset'] def setup(self, offset): - N = 10000 + N = 1000 rng = pd.date_range(start='1/1/2000', periods=N, freq='T') self.data = pd.Series(rng) @@ -86,7 +86,7 @@ class OffsetDatetimeIndexArithmetic(object): param_names = ['offset'] def setup(self, offset): - N = 10000 + N = 1000 self.data = pd.date_range(start='1/1/2000', periods=N, freq='T') def time_add_offset(self, offset): diff --git a/ci/lint.sh b/ci/lint.sh index d678cd1ce5d70..32686f4f55710 100755 --- a/ci/lint.sh +++ b/ci/lint.sh @@ -24,7 +24,7 @@ if [ "$LINT" ]; then echo "Linting setup.py DONE" echo "Linting asv_bench/benchmarks/" - flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/[ijoprs]*.py --ignore=F811 + flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/[is]*.py --ignore=F811 if [ $? -ne "0" ]; then RET=1 fi From f7952bde5f1de49d0e20b40bbc475c74341756e0 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sat, 30 Dec 2017 23:04:45 -0800 Subject: [PATCH 3/3] Do not lint pandas_vb_common.py yet --- ci/lint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/lint.sh b/ci/lint.sh index 32686f4f55710..5380c91831cec 100755 --- a/ci/lint.sh +++ b/ci/lint.sh @@ -24,7 +24,7 @@ if [ "$LINT" ]; then echo "Linting setup.py DONE" echo "Linting asv_bench/benchmarks/" - flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/[is]*.py --ignore=F811 + flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/[ips]*.py --ignore=F811 if [ $? -ne "0" ]; then RET=1 fi