From 0a83814b029e1a79650be8658dd53717b128f8af Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 27 Mar 2019 21:00:24 -0700 Subject: [PATCH 1/7] Removed pandas.core.strings from mypy blacklist --- mypy.ini | 3 --- 1 file changed, 3 deletions(-) diff --git a/mypy.ini b/mypy.ini index b7dbf390fa8c9..270c30b695f7f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -140,9 +140,6 @@ ignore_errors=True [mypy-pandas.core.sparse.frame] ignore_errors=True -[mypy-pandas.core.strings] -ignore_errors=True - [mypy-pandas.core.util.hashing] ignore_errors=True From f6122786fbb5ebe41cf9384ab31baadc06a5416c Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 27 Mar 2019 21:00:41 -0700 Subject: [PATCH 2/7] Refactored _shared_docs for clearer typing support --- pandas/core/strings.py | 74 ++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 579ca75d3685f..f1cda92254426 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -3,6 +3,7 @@ import re import textwrap import warnings +from typing import Dict, Union import numpy as np @@ -28,7 +29,7 @@ "utf-16", "utf-32" ) -_shared_docs = dict() +_shared_docs = dict() # type: Dict[str, str] def cat_core(list_of_columns, sep): @@ -623,13 +624,13 @@ def str_repeat(arr, repeats): dtype: object """ if is_scalar(repeats): - def rep(x): + def scalar_rep(x): try: return compat.binary_type.__mul__(x, repeats) except TypeError: return compat.text_type.__mul__(x, repeats) - return _na_map(rep, arr) + return _na_map(scalar_rep, arr) else: def rep(x, r): @@ -2989,33 +2990,34 @@ def rindex(self, sub, start=0, end=None): 3 sWaPcAsE dtype: object """) - _shared_docs['lower'] = dict(type='lowercase', method='lower', version='') - _shared_docs['upper'] = dict(type='uppercase', method='upper', version='') - _shared_docs['title'] = dict(type='titlecase', method='title', version='') - _shared_docs['capitalize'] = dict(type='be capitalized', - method='capitalize', version='') - _shared_docs['swapcase'] = dict(type='be swapcased', method='swapcase', - version='') - _shared_docs['casefold'] = dict(type='be casefolded', method='casefold', - version='\n .. versionadded:: 0.25.0\n') + _doc_args = {} # type: Dict[str, Dict[str, str]] + _doc_args['lower'] = dict(type='lowercase', method='lower', version='') + _doc_args['upper'] = dict(type='uppercase', method='upper', version='') + _doc_args['title'] = dict(type='titlecase', method='title', version='') + _doc_args['capitalize'] = dict(type='be capitalized', method='capitalize', + version='') + _doc_args['swapcase'] = dict(type='be swapcased', method='swapcase', + version='') + _doc_args['casefold'] = dict(type='be casefolded', method='casefold', + version='\n .. versionadded:: 0.25.0\n') lower = _noarg_wrapper(lambda x: x.lower(), docstring=_shared_docs['casemethods'] % - _shared_docs['lower']) + _doc_args['lower']) upper = _noarg_wrapper(lambda x: x.upper(), docstring=_shared_docs['casemethods'] % - _shared_docs['upper']) + _doc_args['upper']) title = _noarg_wrapper(lambda x: x.title(), docstring=_shared_docs['casemethods'] % - _shared_docs['title']) + _doc_args['title']) capitalize = _noarg_wrapper(lambda x: x.capitalize(), docstring=_shared_docs['casemethods'] % - _shared_docs['capitalize']) + _doc_args['capitalize']) swapcase = _noarg_wrapper(lambda x: x.swapcase(), docstring=_shared_docs['casemethods'] % - _shared_docs['swapcase']) + _doc_args['swapcase']) casefold = _noarg_wrapper(lambda x: x.casefold(), docstring=_shared_docs['casemethods'] % - _shared_docs['casefold']) + _doc_args['casefold']) _shared_docs['ismethods'] = (""" Check whether all characters in each string are %(type)s. @@ -3157,42 +3159,42 @@ def rindex(self, sub, start=0, end=None): 3 False dtype: bool """) - _shared_docs['isalnum'] = dict(type='alphanumeric', method='isalnum') - _shared_docs['isalpha'] = dict(type='alphabetic', method='isalpha') - _shared_docs['isdigit'] = dict(type='digits', method='isdigit') - _shared_docs['isspace'] = dict(type='whitespace', method='isspace') - _shared_docs['islower'] = dict(type='lowercase', method='islower') - _shared_docs['isupper'] = dict(type='uppercase', method='isupper') - _shared_docs['istitle'] = dict(type='titlecase', method='istitle') - _shared_docs['isnumeric'] = dict(type='numeric', method='isnumeric') - _shared_docs['isdecimal'] = dict(type='decimal', method='isdecimal') + _doc_args['isalnum'] = dict(type='alphanumeric', method='isalnum') + _doc_args['isalpha'] = dict(type='alphabetic', method='isalpha') + _doc_args['isdigit'] = dict(type='digits', method='isdigit') + _doc_args['isspace'] = dict(type='whitespace', method='isspace') + _doc_args['islower'] = dict(type='lowercase', method='islower') + _doc_args['isupper'] = dict(type='uppercase', method='isupper') + _doc_args['istitle'] = dict(type='titlecase', method='istitle') + _doc_args['isnumeric'] = dict(type='numeric', method='isnumeric') + _doc_args['isdecimal'] = dict(type='decimal', method='isdecimal') isalnum = _noarg_wrapper(lambda x: x.isalnum(), docstring=_shared_docs['ismethods'] % - _shared_docs['isalnum']) + _doc_args['isalnum']) isalpha = _noarg_wrapper(lambda x: x.isalpha(), docstring=_shared_docs['ismethods'] % - _shared_docs['isalpha']) + _doc_args['isalpha']) isdigit = _noarg_wrapper(lambda x: x.isdigit(), docstring=_shared_docs['ismethods'] % - _shared_docs['isdigit']) + _doc_args['isdigit']) isspace = _noarg_wrapper(lambda x: x.isspace(), docstring=_shared_docs['ismethods'] % - _shared_docs['isspace']) + _doc_args['isspace']) islower = _noarg_wrapper(lambda x: x.islower(), docstring=_shared_docs['ismethods'] % - _shared_docs['islower']) + _doc_args['islower']) isupper = _noarg_wrapper(lambda x: x.isupper(), docstring=_shared_docs['ismethods'] % - _shared_docs['isupper']) + _doc_args['isupper']) istitle = _noarg_wrapper(lambda x: x.istitle(), docstring=_shared_docs['ismethods'] % - _shared_docs['istitle']) + _doc_args['istitle']) isnumeric = _noarg_wrapper(lambda x: x.isnumeric(), docstring=_shared_docs['ismethods'] % - _shared_docs['isnumeric']) + _doc_args['isnumeric']) isdecimal = _noarg_wrapper(lambda x: x.isdecimal(), docstring=_shared_docs['ismethods'] % - _shared_docs['isdecimal']) + _doc_args['isdecimal']) @classmethod def _make_accessor(cls, data): From 590f50c89ba48aae6e1f97570a386c39d03dc4b0 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 27 Mar 2019 21:19:46 -0700 Subject: [PATCH 3/7] isort fixup --- pandas/core/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index f1cda92254426..78df8637e06e8 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2,8 +2,8 @@ import codecs import re import textwrap -import warnings from typing import Dict, Union +import warnings import numpy as np From 2dddb6e2263a336647dfdd15adb7b5ddb8d90e5f Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 27 Mar 2019 22:06:02 -0700 Subject: [PATCH 4/7] Removed unused import --- pandas/core/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 78df8637e06e8..a25dc2d8cf419 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2,7 +2,7 @@ import codecs import re import textwrap -from typing import Dict, Union +from typing import Dict import warnings import numpy as np From a54c73ce9f26ddc3a8cf2d822cd188c2357f2ac1 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Thu, 28 Mar 2019 16:28:15 -0700 Subject: [PATCH 5/7] Fixed broken test --- pandas/tests/api/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 8a0a27a71784c..1dd68eba816fc 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -27,7 +27,7 @@ class TestPDApi(Base): # top-level sub-packages lib = ['api', 'arrays', 'compat', 'core', 'errors', 'pandas', - 'plotting', 'test', 'testing', 'tseries', + 'plotting', 'test', '_testing', 'tseries', 'util', 'options', 'io'] # these are already deprecated; awaiting removal From f4f41626dafcf08abbf84d941413c8a994f6a4d2 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Thu, 28 Mar 2019 16:34:47 -0700 Subject: [PATCH 6/7] Removed inadvertant push --- pandas/tests/api/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py index 1dd68eba816fc..8a0a27a71784c 100644 --- a/pandas/tests/api/test_api.py +++ b/pandas/tests/api/test_api.py @@ -27,7 +27,7 @@ class TestPDApi(Base): # top-level sub-packages lib = ['api', 'arrays', 'compat', 'core', 'errors', 'pandas', - 'plotting', 'test', '_testing', 'tseries', + 'plotting', 'test', 'testing', 'tseries', 'util', 'options', 'io'] # these are already deprecated; awaiting removal From 33c22782117eca6fe335f8509e127ab0efaaaeb2 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 30 Mar 2019 10:40:50 -0700 Subject: [PATCH 7/7] Added comment for _doc_args variable --- pandas/core/strings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 8d89a0e0d967c..6a73f2fc22125 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2990,6 +2990,8 @@ def rindex(self, sub, start=0, end=None): 3 sWaPcAsE dtype: object """) + + # _doc_args holds dict of strings to use in substituting casemethod docs _doc_args = {} # type: Dict[str, Dict[str, str]] _doc_args['lower'] = dict(type='lowercase', method='lower', version='') _doc_args['upper'] = dict(type='uppercase', method='upper', version='')