Skip to content

Commit 6e86773

Browse files
committed
TST: Split timezone preservation test into separate tests
Address review comments on PR #60080 by splitting the comprehensive test into separate focused tests for each set operation (union, intersection, symmetric_difference).
1 parent 9901aa6 commit 6e86773

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

pandas/tests/indexes/datetimes/test_setops.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_union_same_timezone_different_units(self):
201201
expected = date_range("2000-01-01", periods=3, tz="UTC").as_unit("us")
202202
tm.assert_index_equal(result, expected)
203203

204-
def test_setops_same_nonzero_timezone_different_units(self):
204+
def test_union_same_nonzero_timezone_different_units(self):
205205
# GH 60080 - fix timezone being changed to UTC when units differ
206206
# but timezone is the same
207207
tz = "UTC+05:00"
@@ -218,8 +218,14 @@ def test_setops_same_nonzero_timezone_different_units(self):
218218
tm.assert_index_equal(result, expected)
219219
assert result.tz == idx1.tz # Original timezone is preserved
220220

221-
# Test with different dates to ensure it's not just returning one of the inputs
221+
def test_union_different_dates_same_timezone_different_units(self):
222+
# GH 60080 - fix timezone being changed to UTC when units differ
223+
# but timezone is the same
224+
tz = "UTC+05:00"
225+
idx1 = date_range("2000-01-01", periods=3, tz=tz).as_unit("us")
222226
idx3 = date_range("2000-01-03", periods=3, tz=tz).as_unit("us")
227+
228+
# Test with different dates to ensure it's not just returning one of the inputs
223229
result = idx1.union(idx3)
224230
expected = DatetimeIndex(
225231
["2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04", "2000-01-05"],
@@ -228,14 +234,35 @@ def test_setops_same_nonzero_timezone_different_units(self):
228234
tm.assert_index_equal(result, expected)
229235
assert result.tz == idx1.tz # Original timezone is preserved
230236

237+
def test_intersection_same_timezone_different_units(self):
238+
# GH 60080 - fix timezone being changed to UTC when units differ
239+
# but timezone is the same
240+
tz = "UTC+05:00"
241+
idx1 = date_range("2000-01-01", periods=3, tz=tz).as_unit("us")
242+
idx2 = date_range("2000-01-01", periods=3, tz=tz).as_unit("ns")
243+
244+
# Check pre-conditions
245+
assert idx1.tz == idx2.tz
246+
assert idx1.dtype != idx2.dtype # Different units
247+
231248
# Test intersection
232249
result = idx1.intersection(idx2)
233250
expected = date_range("2000-01-01", periods=3, tz=tz).as_unit("ns")
234251
tm.assert_index_equal(result, expected)
235252
assert result.tz == idx1.tz # Original timezone is preserved
236253

237-
# Test symmetric_difference
254+
def test_symmetric_difference_same_timezone_different_units(self):
255+
# GH 60080 - fix timezone being changed to UTC when units differ
256+
# but timezone is the same
257+
tz = "UTC+05:00"
258+
idx1 = date_range("2000-01-01", periods=3, tz=tz).as_unit("us")
238259
idx4 = date_range("2000-01-02", periods=3, tz=tz).as_unit("ns")
260+
261+
# Check pre-conditions
262+
assert idx1.tz == idx4.tz
263+
assert idx1.dtype != idx4.dtype # Different units
264+
265+
# Test symmetric_difference
239266
result = idx1.symmetric_difference(idx4)
240267
expected = DatetimeIndex(["2000-01-01", "2000-01-04"], tz=tz).as_unit("ns")
241268
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)