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

Remove unnecessary usage of _TSObject #17297

Merged
merged 5 commits into from
Aug 21, 2017
Merged
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1176,12 +1176,18 @@ 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)
return datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second,
self.microsecond, self.tzinfo)
ts = convert_to_tsobject(self, self.tzinfo, None, 0, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should add a comment here that self is converted to a TSObject for performance reasons (faster attribute access) for future reference, as I agree you wouldn't necessarily think this

dts = ts.dts
return datetime(dts.year, dts.month, dts.day,
dts.hour, dts.min, dts.sec,
dts.us, ts.tzinfo)

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