-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fixes: [#60084] Added a new file test_timestamp_hash.py #60115
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// | ||
layout: pandas-dev | ||
title: pandas | ||
author: vgauraha62 | ||
/// | ||
|
||
import pandas as pd | ||
import pytest | ||
import logging | ||
|
||
# Starting with logging configuration, to get the insights on the console, important!! | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
def test_timestamp_hash_equality_on_dst(): | ||
logging.info("Testing timestamp hash equality on Daylight Saving Time (DST) transition") | ||
|
||
# This is a DDaylight Saving Time (DST) transition for the America/Los_Angeles time zone | ||
dt_str = "2023-11-05 01:00-08:00" | ||
tz_str = "America/Los_Angeles" | ||
|
||
ts1 = pd.Timestamp(dt_str, tz=tz_str) | ||
logging.info(f"Created timestamp ts1: {ts1}") | ||
|
||
ts2 = ts1 + pd.Timedelta(hours=0) # This here, should create the same timestamp | ||
logging.info(f"Created timestamp ts2: {ts2}") | ||
|
||
# Now we verify that the timestamps compare equal | ||
assert ts1 == ts2, "Timestamps are not considered equal when they should be." | ||
logging.info("Timestamps are equal") | ||
|
||
# Important to Convert to UTC before comparing hash values to avoid Daylight Saving Time (DST) issues | ||
ts1_utc = ts1.tz_convert('UTC') | ||
logging.info(f"Converted ts1 to UTC: {ts1_utc}") | ||
|
||
ts2_utc = ts2.tz_convert('UTC') | ||
logging.info(f"Converted ts2 to UTC: {ts2_utc}") | ||
|
||
# Finally we erify that their hash values are the same, to successfully achieve testing | ||
assert hash(ts1_utc) == hash(ts2_utc), "Hashes of equal Timestamps do not match after normalization." | ||
logging.info("Hashes of timestamps are equal") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Converting to
UTC
before comparing the hashes doesn't replicate the behavior I reported--the bug is one of those "DST issues" thatUTC
avoids 😄. The reported issue is that the hashes of the originalts1
andts2
instances, without normalization, don't have the same hash though they compare equal.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.
i read through it again. maybe i should stop normalizing timestamps to UTC, and start comparing the hash values in their original timezones.