From 28b3abc599237e1bbc67aab1f1de48cc7c1c5163 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 22 Mar 2019 19:06:30 -0700 Subject: [PATCH 01/14] Updated gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 816aff376fc83..f4f64aac23905 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ dist .coverage coverage.xml coverage_html_report +.mypy_cache *.pytest_cache # hypothesis test database .hypothesis/ From a293c49ee3e58ea15137d31129a9174ff9c49b6a Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 22 Mar 2019 19:13:15 -0700 Subject: [PATCH 02/14] Added configuration file --- mypy.ini | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 mypy.ini diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000000000..cf5d2d4cd7c90 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,6 @@ +[mypy] +ignore_missing_imports=True +follow_imports=silent + +[mypy-pandas.conftest,pandas.tests.*] +ignore_errors=True From f831b8856c63c1545b0e6e1a499f6748e65b45a5 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 22 Mar 2019 19:13:28 -0700 Subject: [PATCH 03/14] Fixed syntax error in type hint --- pandas/core/internals/blocks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index a61bc30a126e6..83abca180b03f 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1830,7 +1830,8 @@ def interpolate(self, method='pad', axis=0, inplace=False, limit=None, def shift(self, periods, # type: int axis=0, # type: libinternals.BlockPlacement - fill_value=None): # type: Any + fill_value=None # type: Any + ): # type: (...) -> List[ExtensionBlock] """ Shift the block by `periods`. From 604ae03548de8e1f97ce72545a3b2317c55e0c46 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 22 Mar 2019 19:31:39 -0700 Subject: [PATCH 04/14] Working whitelist of files with current annotations --- mypy_whitelist.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 mypy_whitelist.txt diff --git a/mypy_whitelist.txt b/mypy_whitelist.txt new file mode 100644 index 0000000000000..a968fe48cc7bf --- /dev/null +++ b/mypy_whitelist.txt @@ -0,0 +1,4 @@ +pandas/core/arrays/base.py +pandas/core/arrays/datetimes.py +pandas/core/common.py +pandas/core/dtypes/base.py From ec8e8905c32ef301edec36b80307e6f5f223013e Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 22 Mar 2019 19:52:17 -0700 Subject: [PATCH 05/14] Updated code checks script --- ci/code_checks.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 658c2bc50e87b..92a21da45d637 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -16,9 +16,10 @@ # $ ./ci/code_checks.sh doctests # run doctests # $ ./ci/code_checks.sh docstrings # validate docstring errors # $ ./ci/code_checks.sh dependencies # check that dependencies are consistent +# $ ./ci/code_checks.sh typing # run static type analysis [[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "dependencies" ]] || \ - { echo "Unknown command $1. Usage: $0 [lint|patterns|code|doctests|docstrings|dependencies]"; exit 9999; } + { echo "Unknown command $1. Usage: $0 [lint|patterns|code|doctests|docstrings|dependencies|typing]"; exit 9999; } BASE_DIR="$(dirname $0)/.." RET=0 @@ -256,4 +257,16 @@ if [[ -z "$CHECK" || "$CHECK" == "dependencies" ]]; then fi +### TYPING ### +if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then + + echo "mypy --version" + mypy --version + + MSG='Performing static analysis on items in mypy_whitelist.txt' ; echo $MSG + mypy @mypy_whitelist.txt + RET=$(($RET + $?)) ; echo $MSG "DONE" +fi + + exit $RET From 60d12bc0f76a7b8733081ab06e70cf965a707bde Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 22 Mar 2019 19:59:23 -0700 Subject: [PATCH 06/14] LINT fixup --- pandas/core/internals/blocks.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 83abca180b03f..d8f68de535c2f 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1828,11 +1828,9 @@ def interpolate(self, method='pad', axis=0, inplace=False, limit=None, placement=self.mgr_locs) def shift(self, - periods, # type: int - axis=0, # type: libinternals.BlockPlacement - fill_value=None # type: Any - ): - # type: (...) -> List[ExtensionBlock] + periods: int, + axis: libinternals.BlockPlacement = 0, + fill_value: Any = None) -> List['ExtensionBlock']: """ Shift the block by `periods`. From 63169597ef980def6956f0a5b3343235f9ddbed4 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 23 Mar 2019 14:26:26 -0700 Subject: [PATCH 07/14] Fixed code checks, added to azure-pipelines --- azure-pipelines.yml | 7 +++++++ ci/code_checks.sh | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6c30ec641f292..9b1b17b453af3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -88,6 +88,13 @@ jobs: displayName: 'Docstring validation' condition: true + - script: | + export PATH=$HOME/miniconda3/bin:$PATH + source activate pandas-dev + ci/code_checks.sh typing + displayName: 'Typing validation' + condition: true + - script: | export PATH=$HOME/miniconda3/bin:$PATH source activate pandas-dev diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 92a21da45d637..6396566a1915b 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -18,7 +18,7 @@ # $ ./ci/code_checks.sh dependencies # check that dependencies are consistent # $ ./ci/code_checks.sh typing # run static type analysis -[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "dependencies" ]] || \ +[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "dependencies" ]] || "$1" == "typing" ]] || \ { echo "Unknown command $1. Usage: $0 [lint|patterns|code|doctests|docstrings|dependencies|typing]"; exit 9999; } BASE_DIR="$(dirname $0)/.." From 70e150cbfc48fff1b80ef8b0bce941fe252533e7 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 23 Mar 2019 14:27:04 -0700 Subject: [PATCH 08/14] Added mypy to development dependencies --- environment.yml | 1 + requirements-dev.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/environment.yml b/environment.yml index 41f013c52041c..1d7c8b96216e3 100644 --- a/environment.yml +++ b/environment.yml @@ -19,6 +19,7 @@ dependencies: - hypothesis>=3.82 - isort - moto + - mypy - pycodestyle - pytest>=4.0.2 - pytest-mock diff --git a/requirements-dev.txt b/requirements-dev.txt index ccf2301dad66b..e3034cb99ee80 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -10,6 +10,7 @@ gitpython hypothesis>=3.82 isort moto +mypy pycodestyle pytest>=4.0.2 pytest-mock From c565d7d7e9f596f72143b2f717beed6768145008 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 23 Mar 2019 14:27:31 -0700 Subject: [PATCH 09/14] Changed code check to intentionally fail --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 6396566a1915b..c20f8141f0681 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -264,7 +264,7 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then mypy --version MSG='Performing static analysis on items in mypy_whitelist.txt' ; echo $MSG - mypy @mypy_whitelist.txt + mypy pandas RET=$(($RET + $?)) ; echo $MSG "DONE" fi From b4a0e096f6554d56b9f743c3e666def1cfc64feb Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 23 Mar 2019 15:11:59 -0700 Subject: [PATCH 10/14] Fixed syntax error in code checks script --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index c20f8141f0681..b1406f4848749 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -18,7 +18,7 @@ # $ ./ci/code_checks.sh dependencies # check that dependencies are consistent # $ ./ci/code_checks.sh typing # run static type analysis -[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "dependencies" ]] || "$1" == "typing" ]] || \ +[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "dependencies" || "$1" == "typing" ]] || \ { echo "Unknown command $1. Usage: $0 [lint|patterns|code|doctests|docstrings|dependencies|typing]"; exit 9999; } BASE_DIR="$(dirname $0)/.." From 0c2d01cdb607f93a9a0f5698d042acf543d2d2ad Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 23 Mar 2019 16:28:06 -0700 Subject: [PATCH 11/14] Added whitelist of modules for mypy --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index b1406f4848749..90f369ede6a9a 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -264,7 +264,7 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then mypy --version MSG='Performing static analysis on items in mypy_whitelist.txt' ; echo $MSG - mypy pandas + mypy @mypy_whitelist.txt RET=$(($RET + $?)) ; echo $MSG "DONE" fi From 724d1bff74694ba60ed1ec808f9ec3ed4a059499 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 25 Mar 2019 22:16:37 -0700 Subject: [PATCH 12/14] Self contained blacklist in config file --- mypy.ini | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/mypy.ini b/mypy.ini index cf5d2d4cd7c90..edd36bd27cf55 100644 --- a/mypy.ini +++ b/mypy.ini @@ -4,3 +4,195 @@ follow_imports=silent [mypy-pandas.conftest,pandas.tests.*] ignore_errors=True + +[mypy-pandas._version] +ignore_errors=True + +[mypy-pandas.compat] +ignore_errors=True + +[mypy-pandas.compat.numpy.function] +ignore_errors=True + +[mypy-pandas.compat.pickle_compat] +ignore_errors=True + +[mypy-pandas.core.accessor] +ignore_errors=True + +[mypy-pandas.core.api] +ignore_errors=True + +[mypy-pandas.core.apply] +ignore_errors=True + +[mypy-pandas.core.arrays.array_] +ignore_errors=True + +[mypy-pandas.core.arrays.datetimelike] +ignore_errors=True + +[mypy-pandas.core.arrays.integer] +ignore_errors=True + +[mypy-pandas.core.arrays.interval] +ignore_errors=True + +[mypy-pandas.core.arrays.numpy_] +ignore_errors=True + +[mypy-pandas.core.arrays.period] +ignore_errors=True + +[mypy-pandas.core.arrays.sparse] +ignore_errors=True + +[mypy-pandas.core.arrays.timedeltas] +ignore_errors=True + +[mypy-pandas.core.base] +ignore_errors=True + +[mypy-pandas.core.computation.expr] +ignore_errors=True + +[mypy-pandas.core.computation.ops] +ignore_errors=True + +[mypy-pandas.core.computation.pytables] +ignore_errors=True + +[mypy-pandas.core.config] +ignore_errors=True + +[mypy-pandas.core.config_init] +ignore_errors=True + +[mypy-pandas.core.dtypes.dtypes] +ignore_errors=True + +[mypy-pandas.core.dtypes.missing] +ignore_errors=True + +[mypy-pandas.core.frame] +ignore_errors=True + +[mypy-pandas.core.generic] +ignore_errors=True + +[mypy-pandas.core.groupby.generic] +ignore_errors=True + +[mypy-pandas.core.groupby.groupby] +ignore_errors=True + +[mypy-pandas.core.groupby.ops] +ignore_errors=True + +[mypy-pandas.core.indexes.base] +ignore_errors=True + +[mypy-pandas.core.indexes.datetimelike] +ignore_errors=True + +[mypy-pandas.core.indexes.datetimes] +ignore_errors=True + +[mypy-pandas.core.indexes.period] +ignore_errors=True + +[mypy-pandas.core.indexes.timedeltas] +ignore_errors=True + +[mypy-pandas.core.indexing] +ignore_errors=True + +[mypy-pandas.core.internals.blocks] +ignore_errors=True + +[mypy-pandas.core.ops] +ignore_errors=True + +[mypy-pandas.core.panel] +ignore_errors=True + +[mypy-pandas.core.resample] +ignore_errors=True + +[mypy-pandas.core.reshape.concat] +ignore_errors=True + +[mypy-pandas.core.reshape.merge] +ignore_errors=True + +[mypy-pandas.core.reshape.reshape] +ignore_errors=True + +[mypy-pandas.core.reshape.tile] +ignore_errors=True + +[mypy-pandas.core.series] +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 + +[mypy-pandas.core.window] +ignore_errors=True + +[mypy-pandas.io.clipboards] +ignore_errors=True + +[mypy-pandas.io.feather_format] +ignore_errors=True + +[mypy-pandas.io.formats.css] +ignore_errors=True + +[mypy-pandas.io.html] +ignore_errors=True + +[mypy-pandas.io.json.json] +ignore_errors=True + +[mypy-pandas.io.json.normalize] +ignore_errors=True + +[mypy-pandas.io.json.table_schema] +ignore_errors=True + +[mypy-pandas.io.packers] +ignore_errors=True + +[mypy-pandas.io.parquet] +ignore_errors=True + +[mypy-pandas.io.pytables] +ignore_errors=True + +[mypy-pandas.io.stata] +ignore_errors=True + +[mypy-pandas.plotting._core] +ignore_errors=True + +[mypy-pandas.tseries.frequencies] +ignore_errors=True + +[mypy-pandas.tseries.holiday] +ignore_errors=True + +[mypy-pandas.tseries.offsets] +ignore_errors=True + +[mypy-pandas.util._doctools] +ignore_errors=True + +[mypy-pandas.util.testing] +ignore_errors=True From a16e0b6b5417a745a70bc3e7655e07a89a1313e6 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 25 Mar 2019 22:20:18 -0700 Subject: [PATCH 13/14] Removed whitelist --- ci/code_checks.sh | 4 ++-- mypy_whitelist.txt | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 mypy_whitelist.txt diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 90f369ede6a9a..9f3ded88b5e7d 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -263,8 +263,8 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then echo "mypy --version" mypy --version - MSG='Performing static analysis on items in mypy_whitelist.txt' ; echo $MSG - mypy @mypy_whitelist.txt + MSG='Performing static analysis using mypy' ; echo $MSG + mypy pandas RET=$(($RET + $?)) ; echo $MSG "DONE" fi diff --git a/mypy_whitelist.txt b/mypy_whitelist.txt deleted file mode 100644 index a968fe48cc7bf..0000000000000 --- a/mypy_whitelist.txt +++ /dev/null @@ -1,4 +0,0 @@ -pandas/core/arrays/base.py -pandas/core/arrays/datetimes.py -pandas/core/common.py -pandas/core/dtypes/base.py From 134baabb153f47610ed98c6ec49331b1ed3579a0 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 26 Mar 2019 06:54:02 -0700 Subject: [PATCH 14/14] Added config file to fix error --- mypy.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mypy.ini b/mypy.ini index edd36bd27cf55..b7dbf390fa8c9 100644 --- a/mypy.ini +++ b/mypy.ini @@ -5,6 +5,9 @@ follow_imports=silent [mypy-pandas.conftest,pandas.tests.*] ignore_errors=True +[mypy-pandas._config.config] +ignore_errors=True + [mypy-pandas._version] ignore_errors=True