|
16 | 16 | # $ ./ci/code_checks.sh doctests # run doctests
|
17 | 17 | # $ ./ci/code_checks.sh docstrings # validate docstring errors
|
18 | 18 | # $ ./ci/code_checks.sh dependencies # check that dependencies are consistent
|
| 19 | +# $ ./ci/code_checks.sh typing # run static type analysis |
19 | 20 |
|
20 |
| -[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "dependencies" ]] || \ |
21 |
| - { echo "Unknown command $1. Usage: $0 [lint|patterns|code|doctests|docstrings|dependencies]"; exit 9999; } |
| 21 | +[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "dependencies" || "$1" == "typing" ]] || \ |
| 22 | + { echo "Unknown command $1. Usage: $0 [lint|patterns|code|doctests|docstrings|dependencies|typing]"; exit 9999; } |
22 | 23 |
|
23 | 24 | BASE_DIR="$(dirname $0)/.."
|
24 | 25 | RET=0
|
|
110 | 111 | if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
|
111 | 112 |
|
112 | 113 | # Check for imports from pandas.core.common instead of `import pandas.core.common as com`
|
| 114 | + # Check for imports from collections.abc instead of `from collections import abc` |
113 | 115 | MSG='Check for non-standard imports' ; echo $MSG
|
114 | 116 | invgrep -R --include="*.py*" -E "from pandas.core.common import " pandas
|
| 117 | + invgrep -R --include="*.py*" -E "from collections.abc import " pandas |
115 | 118 | # invgrep -R --include="*.py*" -E "from numpy import nan " pandas # GH#24822 not yet implemented since the offending imports have not all been removed
|
116 | 119 | RET=$(($RET + $?)) ; echo $MSG "DONE"
|
117 | 120 |
|
118 | 121 | MSG='Check for pytest warns' ; echo $MSG
|
119 | 122 | invgrep -r -E --include '*.py' 'pytest\.warns' pandas/tests/
|
120 | 123 | RET=$(($RET + $?)) ; echo $MSG "DONE"
|
121 | 124 |
|
| 125 | + MSG='Check for pytest raises without context' ; echo $MSG |
| 126 | + invgrep -r -E --include '*.py' "[[:space:]] pytest.raises" pandas/tests/ |
| 127 | + RET=$(($RET + $?)) ; echo $MSG "DONE" |
| 128 | + |
122 | 129 | # Check for the following code in testing: `np.testing` and `np.array_equal`
|
123 | 130 | MSG='Check for invalid testing' ; echo $MSG
|
124 | 131 | invgrep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/
|
@@ -175,9 +182,9 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
|
175 | 182 | set -o pipefail
|
176 | 183 | if [[ "$AZURE" == "true" ]]; then
|
177 | 184 | # we exclude all c/cpp files as the c/cpp files of pandas code base are tested when Linting .c and .h files
|
178 |
| - ! grep -n '--exclude=*.'{svg,c,cpp,html} -RI "\s$" * | awk -F ":" '{print "##vso[task.logissue type=error;sourcepath=" $1 ";linenumber=" $2 ";] Tailing whitespaces found: " $3}' |
| 185 | + ! grep -n '--exclude=*.'{svg,c,cpp,html} --exclude-dir=env -RI "\s$" * | awk -F ":" '{print "##vso[task.logissue type=error;sourcepath=" $1 ";linenumber=" $2 ";] Tailing whitespaces found: " $3}' |
179 | 186 | else
|
180 |
| - ! grep -n '--exclude=*.'{svg,c,cpp,html} -RI "\s$" * | awk -F ":" '{print $1 ":" $2 ":Tailing whitespaces found: " $3}' |
| 187 | + ! grep -n '--exclude=*.'{svg,c,cpp,html} --exclude-dir=env -RI "\s$" * | awk -F ":" '{print $1 ":" $2 ":Tailing whitespaces found: " $3}' |
181 | 188 | fi
|
182 | 189 | RET=$(($RET + $?)) ; echo $MSG "DONE"
|
183 | 190 | fi
|
@@ -256,4 +263,16 @@ if [[ -z "$CHECK" || "$CHECK" == "dependencies" ]]; then
|
256 | 263 |
|
257 | 264 | fi
|
258 | 265 |
|
| 266 | +### TYPING ### |
| 267 | +if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then |
| 268 | + |
| 269 | + echo "mypy --version" |
| 270 | + mypy --version |
| 271 | + |
| 272 | + MSG='Performing static analysis using mypy' ; echo $MSG |
| 273 | + mypy pandas |
| 274 | + RET=$(($RET + $?)) ; echo $MSG "DONE" |
| 275 | +fi |
| 276 | + |
| 277 | + |
259 | 278 | exit $RET
|
0 commit comments