From 48a59233078b77b307abec0f4b5a51c585eeeac8 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 24 Aug 2017 16:07:35 -0700 Subject: [PATCH 1/6] Remove property that re-computed microsecond; just accessing the already-existing attribute is about 10x faster than re-computing it --- pandas/_libs/tslib.pyx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index c4a38ec660a4c..4db2b0ba72832 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -548,10 +548,6 @@ class Timestamp(_Timestamp): weekofyear = week - @property - def microsecond(self): - return self._get_field('us') - @property def quarter(self): return self._get_field('q') From aba4053a9dadbdff24e2edc5ced950958091081e Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 25 Aug 2017 09:41:01 -0700 Subject: [PATCH 2/6] Add asv for timestamp property access --- asv_bench/benchmarks/timestamp.py | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 asv_bench/benchmarks/timestamp.py diff --git a/asv_bench/benchmarks/timestamp.py b/asv_bench/benchmarks/timestamp.py new file mode 100644 index 0000000000000..a7a74adc87b4c --- /dev/null +++ b/asv_bench/benchmarks/timestamp.py @@ -0,0 +1,61 @@ +from .pandas_vb_common import * +from pandas import to_timedelta, Timestamp + + +class TimestampProperties(object): + goal_time = 0.2 + + def setup(self): + self.ts = Timestamp('2017-08-25 08:16:14') + + def time_tz(self): + self.ts.tz + + def time_offset(self): + self.ts.offset + + def time_dayofweek(self): + self.ts.dayofweek + + def time_weekday_name(self): + self.ts.weekday_name + + def time_dayofyear(self): + self.ts.dayofyear + + def time_week(self): + self.ts.week + + def time_quarter(self): + self.ts.quarter + + def time_days_in_month(self): + self.ts.days_in_month + + def time_freqstr(self): + self.ts.freqstr + + def time_is_month_start(self): + self.ts.is_month_start + + def time_is_month_end(self): + self.ts.is_month_end + + def time_is_quarter_start(self): + self.ts.is_quarter_start + + def time_is_quarter_end(self): + self.ts.is_quarter_end + + def time_is_year_start(self): + self.ts.is_quarter_end + + def time_is_year_end(self): + self.ts.is_quarter_end + + def time_is_leap_year(self): + self.ts.is_quarter_end + + def time_microsecond(self): + self.ts.microsecond + From 26c0980d4401e1963b6edb1419dbadbed683db67 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 25 Aug 2017 09:43:25 -0700 Subject: [PATCH 3/6] whatsnew note in Performance Imrpovements --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index fcadd26156b1d..04169e006f132 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -325,7 +325,7 @@ Performance Improvements - Improved performance of instantiating :class:`SparseDataFrame` (:issue:`16773`) - :attr:`Series.dt` no longer performs frequency inference, yielding a large speedup when accessing the attribute (:issue:`17210`) - +- `Timestamp.microsecond` no longer re-computes on attribute access. .. _whatsnew_0210.bug_fixes: From 7af49eeeb1860fbf06343653998bac8f6f278b16 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 25 Aug 2017 10:49:48 -0700 Subject: [PATCH 4/6] flake8 whitespace fixup --- asv_bench/benchmarks/timestamp.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/asv_bench/benchmarks/timestamp.py b/asv_bench/benchmarks/timestamp.py index a7a74adc87b4c..066479b22739a 100644 --- a/asv_bench/benchmarks/timestamp.py +++ b/asv_bench/benchmarks/timestamp.py @@ -10,7 +10,7 @@ def setup(self): def time_tz(self): self.ts.tz - + def time_offset(self): self.ts.offset @@ -58,4 +58,3 @@ def time_is_leap_year(self): def time_microsecond(self): self.ts.microsecond - From c98663e5167993c98fb61f69b54ac39f552960e0 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 28 Aug 2017 07:57:33 -0700 Subject: [PATCH 5/6] dummy commit to force CI --- pandas/_libs/period.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/period.pyx b/pandas/_libs/period.pyx index a1d04fea89151..303823f41eb61 100644 --- a/pandas/_libs/period.pyx +++ b/pandas/_libs/period.pyx @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from datetime import datetime, date, timedelta import operator From 9919df441b1ab03e070e08b1b451de32eabc8df8 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Tue, 29 Aug 2017 07:47:38 -0700 Subject: [PATCH 6/6] rst fixup, add GH reference --- doc/source/whatsnew/v0.21.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 04169e006f132..6fec3db91cc51 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -325,7 +325,7 @@ Performance Improvements - Improved performance of instantiating :class:`SparseDataFrame` (:issue:`16773`) - :attr:`Series.dt` no longer performs frequency inference, yielding a large speedup when accessing the attribute (:issue:`17210`) -- `Timestamp.microsecond` no longer re-computes on attribute access. +- :attr:`Timestamp.microsecond` no longer re-computes on attribute access (:issue:`17331`) .. _whatsnew_0210.bug_fixes: