Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

tqa236
Copy link
Contributor

@tqa236 tqa236 commented Mar 8, 2024

Comment on lines +385 to +390
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.
Copy link
Member

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 from datetime.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?

@datapythonista datapythonista changed the title Clarify doc for converting timestamps to epoch DOC: Clarify doc for converting timestamps to epoch Mar 14, 2024
@tqa236 tqa236 closed this Mar 17, 2024
@tqa236 tqa236 deleted the clarify-doc branch March 17, 2024 07:53
@tqa236 tqa236 restored the clarify-doc branch March 17, 2024 07:53
@tqa236 tqa236 reopened this Mar 17, 2024
@tqa236
Copy link
Contributor Author

tqa236 commented Mar 17, 2024

Sorry, I was not meant to close this PR. I closed it by accident when cleaning up my fork

Copy link
Contributor

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.

@github-actions github-actions bot added the Stale label Apr 17, 2024
@mroeschke
Copy link
Member

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

@mroeschke mroeschke closed this Apr 23, 2024
@tqa236 tqa236 deleted the clarify-doc branch April 23, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: why is subtracting 1/1/1970 recommended over the .timestamp() method?
3 participants