diff --git a/asv_bench/benchmarks/timestamp.py b/asv_bench/benchmarks/timestamp.py index e4f3023037580..e8cb4c9d1c75b 100644 --- a/asv_bench/benchmarks/timestamp.py +++ b/asv_bench/benchmarks/timestamp.py @@ -81,3 +81,9 @@ def time_replace_across_dst(self): def time_replace_None(self): self.ts_tz.replace(tzinfo=None) + + def time_to_pydatetime(self): + self.ts.to_pydatetime() + + def time_to_pydatetime_tz(self): + self.ts_tz.to_pydatetime() diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index 8238552b44e03..6ba37062ac869 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -1158,18 +1158,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 """