@@ -31,7 +31,9 @@ from pandas import (
31
31
PeriodDtype ,
32
32
PeriodIndex ,
33
33
Series ,
34
+ Timedelta ,
34
35
TimedeltaIndex ,
36
+ Timestamp ,
35
37
)
36
38
from pandas .core .arrays import ExtensionArray
37
39
from pandas .core .base import IndexOpsMixin
@@ -60,6 +62,7 @@ from pandas._typing import (
60
62
GenericT_co ,
61
63
HashableT ,
62
64
IgnoreRaise ,
65
+ Just ,
63
66
Label ,
64
67
Level ,
65
68
MaskType ,
@@ -77,12 +80,23 @@ from pandas._typing import (
77
80
np_ndarray_complex ,
78
81
np_ndarray_float ,
79
82
np_ndarray_str ,
83
+ np_ndarray_td ,
80
84
type_t ,
81
85
)
82
86
83
87
class InvalidIndexError (Exception ): ...
84
88
85
89
_ListLike : TypeAlias = ArrayLike | dict [_str , np .ndarray ] | SequenceNotStr [S1 ]
90
+ _NumListLike : TypeAlias = (
91
+ ExtensionArray
92
+ | np_ndarray_bool
93
+ | np_ndarray_anyint
94
+ | np_ndarray_float
95
+ | np_ndarray_complex
96
+ | dict [_str , np .ndarray ]
97
+ | Sequence [complex ]
98
+ | IndexOpsMixin [complex ]
99
+ )
86
100
87
101
class Index (IndexOpsMixin [S1 ]):
88
102
__hash__ : ClassVar [None ] # type: ignore[assignment]
@@ -626,6 +640,156 @@ class Index(IndexOpsMixin[S1]):
626
640
self : Index [_str ], other : _str | Sequence [_str ] | np_ndarray_str | Index [_str ]
627
641
) -> Index [_str ]: ...
628
642
@overload
643
+ def __sub__ (self : Index [Never ], other : DatetimeIndex ) -> Never : ...
644
+ @overload
645
+ def __sub__ (self : Index [Never ], other : complex | _NumListLike | Index ) -> Index : ...
646
+ @overload
647
+ def __sub__ (self , other : Index [Never ]) -> Index : ... # type: ignore[overload-overlap]
648
+ @overload
649
+ def __sub__ (
650
+ self : Index [bool ],
651
+ other : Just [int ] | Sequence [Just [int ]] | np_ndarray_anyint | Index [int ],
652
+ ) -> Index [int ]: ...
653
+ @overload
654
+ def __sub__ (
655
+ self : Index [bool ],
656
+ other : Just [float ] | Sequence [Just [float ]] | np_ndarray_float | Index [float ],
657
+ ) -> Index [float ]: ...
658
+ @overload
659
+ def __sub__ (
660
+ self : Index [int ],
661
+ other : (
662
+ int
663
+ | Sequence [int ]
664
+ | np_ndarray_bool
665
+ | np_ndarray_anyint
666
+ | Index [bool ]
667
+ | Index [int ]
668
+ ),
669
+ ) -> Index [int ]: ...
670
+ @overload
671
+ def __sub__ (
672
+ self : Index [int ],
673
+ other : Just [float ] | Sequence [Just [float ]] | np_ndarray_float | Index [float ],
674
+ ) -> Index [float ]: ...
675
+ @overload
676
+ def __sub__ (
677
+ self : Index [float ],
678
+ other : (
679
+ float
680
+ | Sequence [float ]
681
+ | np_ndarray_bool
682
+ | np_ndarray_anyint
683
+ | np_ndarray_float
684
+ | Index [bool ]
685
+ | Index [int ]
686
+ | Index [float ]
687
+ ),
688
+ ) -> Index [float ]: ...
689
+ @overload
690
+ def __sub__ (
691
+ self : Index [complex ],
692
+ other : (
693
+ T_COMPLEX
694
+ | Sequence [T_COMPLEX ]
695
+ | np_ndarray_bool
696
+ | np_ndarray_anyint
697
+ | np_ndarray_float
698
+ | Index [T_COMPLEX ]
699
+ ),
700
+ ) -> Index [complex ]: ...
701
+ @overload
702
+ def __sub__ (
703
+ self : Index [T_COMPLEX ],
704
+ other : (
705
+ Just [complex ]
706
+ | Sequence [Just [complex ]]
707
+ | np_ndarray_complex
708
+ | Index [complex ]
709
+ ),
710
+ ) -> Index [complex ]: ...
711
+ @overload
712
+ def __sub__ (
713
+ self : Index [Timestamp ],
714
+ other : timedelta | np .timedelta64 | np_ndarray_td | TimedeltaIndex ,
715
+ ) -> DatetimeIndex : ...
716
+ @overload
717
+ def __sub__ (
718
+ self : Index [Timedelta ],
719
+ other : timedelta | np .timedelta64 | np_ndarray_td | TimedeltaIndex ,
720
+ ) -> TimedeltaIndex : ...
721
+ @overload
722
+ def __rsub__ (self : Index [Never ], other : DatetimeIndex ) -> Never : ... # type: ignore[misc]
723
+ @overload
724
+ def __rsub__ (
725
+ self : Index [Never ], other : complex | _NumListLike | Index
726
+ ) -> Index : ...
727
+ @overload
728
+ def __rsub__ (self , other : Index [Never ]) -> Index : ...
729
+ @overload
730
+ def __rsub__ (
731
+ self : Index [bool ],
732
+ other : Just [int ] | Sequence [Just [int ]] | np_ndarray_anyint | Index [int ],
733
+ ) -> Index [int ]: ...
734
+ @overload
735
+ def __rsub__ (
736
+ self : Index [bool ],
737
+ other : Just [float ] | Sequence [Just [float ]] | np_ndarray_float | Index [float ],
738
+ ) -> Index [float ]: ...
739
+ @overload
740
+ def __rsub__ (
741
+ self : Index [int ],
742
+ other : (
743
+ int
744
+ | Sequence [int ]
745
+ | np_ndarray_bool
746
+ | np_ndarray_anyint
747
+ | Index [bool ]
748
+ | Index [int ]
749
+ ),
750
+ ) -> Index [int ]: ...
751
+ @overload
752
+ def __rsub__ (
753
+ self : Index [int ],
754
+ other : Just [float ] | Sequence [Just [float ]] | np_ndarray_float | Index [float ],
755
+ ) -> Index [float ]: ...
756
+ @overload
757
+ def __rsub__ (
758
+ self : Index [float ],
759
+ other : (
760
+ float
761
+ | Sequence [float ]
762
+ | np_ndarray_bool
763
+ | np_ndarray_anyint
764
+ | np_ndarray_float
765
+ | Index [bool ]
766
+ | Index [int ]
767
+ | Index [float ]
768
+ ),
769
+ ) -> Index [float ]: ...
770
+ @overload
771
+ def __rsub__ (
772
+ self : Index [complex ],
773
+ other : (
774
+ T_COMPLEX
775
+ | Sequence [T_COMPLEX ]
776
+ | np_ndarray_bool
777
+ | np_ndarray_anyint
778
+ | np_ndarray_float
779
+ | Index [T_COMPLEX ]
780
+ ),
781
+ ) -> Index [complex ]: ...
782
+ @overload
783
+ def __rsub__ (
784
+ self : Index [T_COMPLEX ],
785
+ other : (
786
+ Just [complex ]
787
+ | Sequence [Just [complex ]]
788
+ | np_ndarray_complex
789
+ | Index [complex ]
790
+ ),
791
+ ) -> Index [complex ]: ...
792
+ @overload
629
793
def __mul__ (
630
794
self : Index [int ] | Index [float ], other : timedelta
631
795
) -> TimedeltaIndex : ...
0 commit comments