Skip to content

Commit 47cff99

Browse files
committed
Added a new file test_timestamp_hash.py
1 parent 8d2ca0b commit 47cff99

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/scalar/test_timestamp_hash.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
///
2+
layout: pandas-dev
3+
title: pandas
4+
author: vgauraha62
5+
///
6+
7+
import pandas as pd
8+
import pytest
9+
import logging
10+
11+
# Starting with logging configuration, to get the insights on the console, important!!
12+
logging.basicConfig(level=logging.INFO)
13+
14+
def test_timestamp_hash_equality_on_dst():
15+
logging.info("Testing timestamp hash equality on Daylight Saving Time (DST) transition")
16+
17+
# This is a DDaylight Saving Time (DST) transition for the America/Los_Angeles time zone
18+
dt_str = "2023-11-05 01:00-08:00"
19+
tz_str = "America/Los_Angeles"
20+
21+
ts1 = pd.Timestamp(dt_str, tz=tz_str)
22+
logging.info(f"Created timestamp ts1: {ts1}")
23+
24+
ts2 = ts1 + pd.Timedelta(hours=0) # This here, should create the same timestamp
25+
logging.info(f"Created timestamp ts2: {ts2}")
26+
27+
# Now we verify that the timestamps compare equal
28+
assert ts1 == ts2, "Timestamps are not considered equal when they should be."
29+
logging.info("Timestamps are equal")
30+
31+
# Important to Convert to UTC before comparing hash values to avoid Daylight Saving Time (DST) issues
32+
ts1_utc = ts1.tz_convert('UTC')
33+
logging.info(f"Converted ts1 to UTC: {ts1_utc}")
34+
35+
ts2_utc = ts2.tz_convert('UTC')
36+
logging.info(f"Converted ts2 to UTC: {ts2_utc}")
37+
38+
# Finally we erify that their hash values are the same, to successfully achieve testing
39+
assert hash(ts1_utc) == hash(ts2_utc), "Hashes of equal Timestamps do not match after normalization."
40+
logging.info("Hashes of timestamps are equal")

0 commit comments

Comments
 (0)