@@ -5,17 +5,25 @@ from typing import (
55 Generic ,
66 Literal ,
77 Sequence ,
8+ TypeVar ,
89 overload ,
910)
1011
1112import numpy as np
1213import pandas as pd
13- from pandas import Series
14+ from pandas import (
15+ DataFrame ,
16+ MultiIndex ,
17+ Series ,
18+ )
1419from pandas .core .base import NoNewAttributesMixin
1520
1621from pandas ._typing import T
1722
18- class StringMethods (NoNewAttributesMixin , Generic [T ]):
23+ # The _TS type is what is used for the result of str.split with expand=True
24+ _TS = TypeVar ("_TS" , DataFrame , MultiIndex )
25+
26+ class StringMethods (NoNewAttributesMixin , Generic [T , _TS ]):
1927 def __init__ (self , data : T ) -> None : ...
2028 def __getitem__ (self , key : slice | int ) -> T : ...
2129 def __iter__ (self ) -> T : ...
@@ -44,11 +52,21 @@ class StringMethods(NoNewAttributesMixin, Generic[T]):
4452 na_rep : str | None = ...,
4553 join : Literal ["left" , "right" , "outer" , "inner" ] = ...,
4654 ) -> T : ...
55+ @overload
56+ def split (
57+ self , pat : str = ..., n : int = ..., * , expand : Literal [True ], regex : bool = ...
58+ ) -> _TS : ...
59+ @overload
4760 def split (
48- self , pat : str = ..., n : int = ..., expand : bool = ..., * , regex : bool = ...
61+ self , pat : str = ..., n : int = ..., * , expand : bool = ..., regex : bool = ...
4962 ) -> T : ...
63+ @overload
64+ def rsplit (
65+ self , pat : str = ..., n : int = ..., * , expand : Literal [True ], regex : bool = ...
66+ ) -> T : ...
67+ @overload
5068 def rsplit (
51- self , pat : str = ..., n : int = ..., expand : bool = ..., * , regex : bool = ...
69+ self , pat : str = ..., n : int = ..., * , expand : bool = ..., regex : bool = ...
5270 ) -> T : ...
5371 @overload
5472 def partition (self , sep : str = ...) -> pd .DataFrame : ...
0 commit comments