-
-
Notifications
You must be signed in to change notification settings - Fork 146
Fix annotations of str methods that accept regular expressions #1278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -83,12 +83,17 @@ class StringMethods( | |||
) -> _T_STR: ... | |||
@overload | |||
def split( | |||
self, pat: str = ..., *, n: int = ..., expand: Literal[True], regex: bool = ... | |||
self, | |||
pat: str | re.Pattern[str] = ..., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) -> _T_BOOL: ... | ||
def replace( | ||
self, | ||
pat: str, | ||
pat: str | re.Pattern[str], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -180,18 +189,26 @@ class StringMethods( | |||
def count(self, pat: str, flags: int = ...) -> _T_INT: ... | |||
def startswith(self, pat: str | tuple[str, ...], na: Any = ...) -> _T_BOOL: ... | |||
def endswith(self, pat: str | tuple[str, ...], na: Any = ...) -> _T_BOOL: ... | |||
def findall(self, pat: str, flags: int = ...) -> _T_LIST_STR: ... | |||
def findall(self, pat: str | re.Pattern[str], flags: int = ...) -> _T_LIST_STR: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@overload | ||
def extract( | ||
self, pat: str, flags: int = ..., *, expand: Literal[True] = ... | ||
self, | ||
pat: str | re.Pattern[str], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) -> _T_OBJECT: ... | ||
def extractall(self, pat: str, flags: int = ...) -> pd.DataFrame: ... | ||
def extractall( | ||
self, pat: str | re.Pattern[str], flags: int = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -214,7 +231,11 @@ class StringMethods( | |||
def isnumeric(self) -> _T_BOOL: ... | |||
def isdecimal(self) -> _T_BOOL: ... | |||
def fullmatch( | |||
self, pat: str, case: bool = ..., flags: int = ..., na: Any = ... | |||
self, | |||
pat: str | re.Pattern[str], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -133,11 +138,15 @@ class StringMethods( | |||
regex: bool = ..., | |||
) -> _T_BOOL: ... | |||
def match( | |||
self, pat: str, case: bool = ..., flags: int = ..., na: Any = ... | |||
self, | |||
pat: str | re.Pattern[str], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only one of the changed methods that is not documented as accepting a compiled regex but this is an oversight https://pandas.pydata.org/docs/reference/api/pandas.Series.str.match.html. See pandas-dev/pandas#61879
Thank you for your well-tested PR!
It is not clear to me if the documentation suggests that Feel free to open an issue/PR at pandas about it. |
assert_type()
to assert the type of any return valueThese methods accept compiled regular expressions as documented in pandas and tested at runtime.