@@ -201,7 +201,7 @@ def test_union_same_timezone_different_units(self):
201
201
expected = date_range ("2000-01-01" , periods = 3 , tz = "UTC" ).as_unit ("us" )
202
202
tm .assert_index_equal (result , expected )
203
203
204
- def test_setops_same_nonzero_timezone_different_units (self ):
204
+ def test_union_same_nonzero_timezone_different_units (self ):
205
205
# GH 60080 - fix timezone being changed to UTC when units differ
206
206
# but timezone is the same
207
207
tz = "UTC+05:00"
@@ -218,8 +218,14 @@ def test_setops_same_nonzero_timezone_different_units(self):
218
218
tm .assert_index_equal (result , expected )
219
219
assert result .tz == idx1 .tz # Original timezone is preserved
220
220
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" )
222
226
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
223
229
result = idx1 .union (idx3 )
224
230
expected = DatetimeIndex (
225
231
["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):
228
234
tm .assert_index_equal (result , expected )
229
235
assert result .tz == idx1 .tz # Original timezone is preserved
230
236
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
+
231
248
# Test intersection
232
249
result = idx1 .intersection (idx2 )
233
250
expected = date_range ("2000-01-01" , periods = 3 , tz = tz ).as_unit ("ns" )
234
251
tm .assert_index_equal (result , expected )
235
252
assert result .tz == idx1 .tz # Original timezone is preserved
236
253
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" )
238
259
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
239
266
result = idx1 .symmetric_difference (idx4 )
240
267
expected = DatetimeIndex (["2000-01-01" , "2000-01-04" ], tz = tz ).as_unit ("ns" )
241
268
tm .assert_index_equal (result , expected )
0 commit comments