Skip to content

[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

Merged
merged 1 commit into from
May 21, 2021

Conversation

simonjayhawkins
Copy link
Member

pre-cursor to #41590

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label May 21, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone May 21, 2021
@@ -1,12 +1,12 @@
from __future__ import annotations

import codecs
from collections.abc import Callable # noqa: PDF001
Copy link
Member Author

@simonjayhawkins simonjayhawkins May 21, 2021

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,
Copy link
Member Author

@simonjayhawkins simonjayhawkins May 21, 2021

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)
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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.

@jreback jreback merged commit 70d4697 into pandas-dev:master May 21, 2021
@jreback
Copy link
Contributor

jreback commented May 21, 2021

thanks @simonjayhawkins

@simonjayhawkins simonjayhawkins deleted the typing-replace branch May 21, 2021 15:19
TLouf pushed a commit to TLouf/pandas that referenced this pull request Jun 1, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants