From 702a970f42f364584a7f8d0ae95045c0a38bf775 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Tue, 19 Sep 2017 10:38:05 -0700 Subject: [PATCH 1/4] Simplify to_pydatetime() --- pandas/_libs/tslib.pyx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index ec12611ae7f02..b76bd5c62f1ea 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -1157,18 +1157,13 @@ cdef class _Timestamp(datetime): If warn=True, issue a warning if nanoseconds is nonzero. """ - cdef: - pandas_datetimestruct dts - _TSObject ts - if self.nanosecond != 0 and warn: warnings.warn("Discarding nonzero nanoseconds in conversion", UserWarning, stacklevel=2) - ts = convert_to_tsobject(self, self.tzinfo, None, 0, 0) - dts = ts.dts - return datetime(dts.year, dts.month, dts.day, - dts.hour, dts.min, dts.sec, - dts.us, ts.tzinfo) + + return datetime(self.year, self.month, self.day, + self.hour, self.minute, self.second, + self.microsecond, self.tzinfo) cpdef to_datetime64(self): """ Returns a numpy.datetime64 object with 'ns' precision """ From 07c1d1d01c129f92c398f819767693d96250565b Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Tue, 19 Sep 2017 19:12:21 -0700 Subject: [PATCH 2/4] indendentation fixup --- pandas/_libs/tslib.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index b76bd5c62f1ea..cf8e78028b52f 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -1162,8 +1162,8 @@ cdef class _Timestamp(datetime): UserWarning, stacklevel=2) return datetime(self.year, self.month, self.day, - self.hour, self.minute, self.second, - self.microsecond, self.tzinfo) + self.hour, self.minute, self.second, + self.microsecond, self.tzinfo) cpdef to_datetime64(self): """ Returns a numpy.datetime64 object with 'ns' precision """ From 3438440116f3a24da09783ca810beee10f32aa5b Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 20 Sep 2017 07:25:26 -0700 Subject: [PATCH 3/4] Add asv benchmarks --- asv_bench/benchmarks/timestamp.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/asv_bench/benchmarks/timestamp.py b/asv_bench/benchmarks/timestamp.py index 066479b22739a..06e9e98e3a16e 100644 --- a/asv_bench/benchmarks/timestamp.py +++ b/asv_bench/benchmarks/timestamp.py @@ -58,3 +58,15 @@ def time_is_leap_year(self): def time_microsecond(self): self.ts.microsecond + + +class TimestampMethods(object): + def setup(self): + self.ts = Timestamp('2017-08-25 08:16:14') + self.ts_tz = Timestamp('2017-08-25 08:16:14', tz='Europe/Brussels') + + def time_to_pydatetime(self): + self.ts.to_pydatetime() + + def time_to_pydatetime_tz(self): + self.ts_tz.to_pydatetime() From e6732090185cd0077adafa459b7b023a9141d367 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 20 Sep 2017 07:49:52 -0700 Subject: [PATCH 4/4] flake8 whitespace fixup --- asv_bench/benchmarks/timestamp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/asv_bench/benchmarks/timestamp.py b/asv_bench/benchmarks/timestamp.py index 25b0439b2055b..e8cb4c9d1c75b 100644 --- a/asv_bench/benchmarks/timestamp.py +++ b/asv_bench/benchmarks/timestamp.py @@ -87,4 +87,3 @@ def time_to_pydatetime(self): def time_to_pydatetime_tz(self): self.ts_tz.to_pydatetime() -