-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Clarify doc for converting timestamps to epoch #57777
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
Conversation
We encourage explicitly subtracting 1970-01-01 from the timestamps over using the | ||
``.timestamp`` method because the ``Timestamp.timestamp`` method in pandas exhibits a | ||
distinct behavior compared to ``datetime.timestamp``, particularly in cases involving | ||
timezone-naive (tznaive) instances. Specifically, ``Timestamp.timestamp`` treats | ||
timezone-naive datetime objects as UTC by default while the ``datetime.timestamp`` | ||
method treats them as implicitly belonging to the system's local timezone. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tqa236, but while you say it's true, I think @jbrockmendel's comment was taken out of context.
The reason we are manually substracting the date in the example above it's not because datetime.datetime.timestamp
uses the local timezone, which we don't like. The reason is because the stamps
object is a DateTimeIndex
which doesn't implement a method to get the epoch value. Personally, it feels a bit strange to have this section in the user guide and not have a timestamp
method in both DateTimeIndex
and the dt
accessor. That's a different topic that we can discuss, but for now, there are two independent things getting mixed here:
- Whether we want to continue to use the manual subtraction in the example, or we want another alternative like the one proposed in the issue
stamps.map(lambda x: x.timestamp())
(which does not use the local timezone) - Adding a note clarifying that pandas'
Timestamp.timestamp
is different fromdatetime.datetime.timestamp
for timezone-naive objects
I think for this PR it's fine to keep the note (the beginning should be changed) since there is no .timestamp
method as you say, and if recommend subtracting the date is because there is no other vectorized way (that I know) using the public API. But that would be unrelated to the note, and it's what I'd address in a second PR, after further discussion in the issue on what we really want to do:
- Do recommend subtracting the dates
- Implement
.timestamp
- Recommend using the simpler not vectorized way with
.map
@jbrockmendel @MarcoGorelli does it make sense to you what I say?
Sorry, I was not meant to close this PR. I closed it by accident when cleaning up my fork |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Thanks for the pull request, but it appears to have gone stale. Additionally it seems like more discussion is needed in the issue on what we actually want to include in the docs so closing for now |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.