-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[ArrowStringArray] TYP: add annotations to str.replace #41603
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
Conversation
@@ -1,12 +1,12 @@ | |||
from __future__ import annotations | |||
|
|||
import codecs | |||
from collections.abc import Callable # noqa: PDF001 |
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.
we should disable the custom pandas flake rule.
we should be importing Callable from collections.abc
https://docs.python.org/3/library/typing.html#callable
from functools import wraps | ||
import re | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Hashable, | ||
Pattern, |
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.
we should not be using Pattern from typing.
https://www.python.org/dev/peps/pep-0585/
Importing those from typing is deprecated
if regex and (is_compiled_re or len(pat) > 1 or flags or callable(repl)): | ||
if not is_compiled_re: | ||
if regex and ( | ||
isinstance(pat, re.Pattern) or len(pat) > 1 or flags or callable(repl) |
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.
mypy cannot narrow types with is_compiled_re
@@ -1374,6 +1378,9 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None): | |||
elif callable(repl): | |||
raise ValueError("Cannot use a callable replacement when regex=False") | |||
|
|||
if case is None: | |||
case = True |
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.
changed so that case is not optional on array methods. all validation is done here.
@@ -1,7 +1,8 @@ | |||
from __future__ import annotations | |||
|
|||
import abc | |||
from typing import Pattern | |||
from collections.abc import Callable # noqa: PDF001 |
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.
another reason to disable the flake rule. abc is imported.
thanks @simonjayhawkins |
pre-cursor to #41590