@@ -31,7 +31,9 @@ from pandas import (
3131 PeriodDtype ,
3232 PeriodIndex ,
3333 Series ,
34+ Timedelta ,
3435 TimedeltaIndex ,
36+ Timestamp ,
3537)
3638from pandas .core .arrays import ExtensionArray
3739from pandas .core .base import IndexOpsMixin
@@ -60,6 +62,7 @@ from pandas._typing import (
6062 GenericT_co ,
6163 HashableT ,
6264 IgnoreRaise ,
65+ Just ,
6366 Label ,
6467 Level ,
6568 MaskType ,
@@ -77,12 +80,23 @@ from pandas._typing import (
7780 np_ndarray_complex ,
7881 np_ndarray_float ,
7982 np_ndarray_str ,
83+ np_ndarray_td ,
8084 type_t ,
8185)
8286
8387class InvalidIndexError (Exception ): ...
8488
8589_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+ )
86100
87101class Index (IndexOpsMixin [S1 ]):
88102 __hash__ : ClassVar [None ] # type: ignore[assignment]
@@ -626,6 +640,156 @@ class Index(IndexOpsMixin[S1]):
626640 self : Index [_str ], other : _str | Sequence [_str ] | np_ndarray_str | Index [_str ]
627641 ) -> Index [_str ]: ...
628642 @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
629793 def __mul__ (
630794 self : Index [int ] | Index [float ], other : timedelta
631795 ) -> TimedeltaIndex : ...
0 commit comments