Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify to_pydatetime() #17592

Merged
merged 6 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions asv_bench/benchmarks/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
13 changes: 4 additions & 9 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down