Skip to content

Commit 49cfdd7

Browse files
jbrockmendeljreback
authored andcommitted
Simplify to_pydatetime() (#17592)
1 parent 26681db commit 49cfdd7

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

asv_bench/benchmarks/timestamp.py

+6
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ def time_replace_across_dst(self):
8181

8282
def time_replace_None(self):
8383
self.ts_tz.replace(tzinfo=None)
84+
85+
def time_to_pydatetime(self):
86+
self.ts.to_pydatetime()
87+
88+
def time_to_pydatetime_tz(self):
89+
self.ts_tz.to_pydatetime()

pandas/_libs/tslib.pyx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1158,18 +1158,13 @@ cdef class _Timestamp(datetime):
11581158
11591159
If warn=True, issue a warning if nanoseconds is nonzero.
11601160
"""
1161-
cdef:
1162-
pandas_datetimestruct dts
1163-
_TSObject ts
1164-
11651161
if self.nanosecond != 0 and warn:
11661162
warnings.warn("Discarding nonzero nanoseconds in conversion",
11671163
UserWarning, stacklevel=2)
1168-
ts = convert_to_tsobject(self, self.tzinfo, None, 0, 0)
1169-
dts = ts.dts
1170-
return datetime(dts.year, dts.month, dts.day,
1171-
dts.hour, dts.min, dts.sec,
1172-
dts.us, ts.tzinfo)
1164+
1165+
return datetime(self.year, self.month, self.day,
1166+
self.hour, self.minute, self.second,
1167+
self.microsecond, self.tzinfo)
11731168

11741169
cpdef to_datetime64(self):
11751170
""" Returns a numpy.datetime64 object with 'ns' precision """

0 commit comments

Comments
 (0)