@@ -694,3 +694,79 @@ def test_intersection_non_nano_rangelike():
694694 freq = "D" ,
695695 )
696696 tm .assert_index_equal (result , expected )
697+
698+
699+ def test_union_preserves_timezone_and_resolution ():
700+ """
701+ GH 60080: Ensure union of DatetimeIndex with the same timezone
702+ and differing resolutions results in the higher resolution unit
703+ and preserves the timezone.
704+ """
705+ idx1 = DatetimeIndex (["2020-01-01 10:00:00+05:00" ]).astype (
706+ "datetime64[us, UTC+05:00]"
707+ )
708+ idx2 = DatetimeIndex (["2020-01-01 10:00:00+05:00" ]).astype (
709+ "datetime64[ns, UTC+05:00]"
710+ )
711+ result = idx1 .union (idx2 )
712+ expected = DatetimeIndex (["2020-01-01 10:00:00+05:00" ]).astype (
713+ "datetime64[ns, UTC+05:00]"
714+ )
715+ tm .assert_index_equal (result , expected )
716+
717+
718+ def test_union_multiple_entries_same_timezone ():
719+ """
720+ GH 60080: Test union with multiple DatetimeIndex entries having the same timezone
721+ and different units, ensuring correct alignment and resolution preservation.
722+ """
723+ idx1 = DatetimeIndex (
724+ ["2023-01-01 10:00:00+05:00" , "2023-01-02 10:00:00+05:00" ]
725+ ).astype ("datetime64[us, UTC+05:00]" )
726+ idx2 = DatetimeIndex (
727+ ["2023-01-01 10:00:00+05:00" , "2023-01-03 10:00:00+05:00" ]
728+ ).astype ("datetime64[ns, UTC+05:00]" )
729+ result = idx1 .union (idx2 )
730+ expected = DatetimeIndex (
731+ [
732+ "2023-01-01 10:00:00+05:00" ,
733+ "2023-01-02 10:00:00+05:00" ,
734+ "2023-01-03 10:00:00+05:00" ,
735+ ]
736+ ).astype ("datetime64[ns, UTC+05:00]" )
737+ tm .assert_index_equal (result , expected )
738+
739+
740+ def test_union_same_timezone_same_resolution ():
741+ """
742+ GH 60080: Ensure union of DatetimeIndex with the same timezone and
743+ resolution is straightforward and retains the resolution.
744+ """
745+ idx1 = DatetimeIndex (["2022-01-01 15:00:00+05:00" ]).astype (
746+ "datetime64[ms, UTC+05:00]"
747+ )
748+ idx2 = DatetimeIndex (["2022-01-01 16:00:00+05:00" ]).astype (
749+ "datetime64[ms, UTC+05:00]"
750+ )
751+ result = idx1 .union (idx2 )
752+ expected = DatetimeIndex (
753+ ["2022-01-01 15:00:00+05:00" , "2022-01-01 16:00:00+05:00" ]
754+ ).astype ("datetime64[ms, UTC+05:00]" )
755+ tm .assert_index_equal (result , expected )
756+
757+ def test_union_single_entry ():
758+ """
759+ GH 60080: Ensure union of single-entry DatetimeIndex works as expected
760+ with different units and same timezone.
761+ """
762+ idx1 = DatetimeIndex (["2023-01-01 10:00:00+05:00" ]).astype (
763+ "datetime64[ms, UTC+05:00]"
764+ )
765+ idx2 = DatetimeIndex (["2023-01-01 10:00:00+05:00" ]).astype (
766+ "datetime64[us, UTC+05:00]"
767+ )
768+ result = idx1 .union (idx2 )
769+ expected = DatetimeIndex (["2023-01-01 10:00:00+05:00" ]).astype (
770+ "datetime64[us, UTC+05:00]"
771+ )
772+ tm .assert_index_equal (result , expected )
0 commit comments