diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df10e352881442..e7738fb9a29793 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,12 +56,44 @@ repos: - id: incorrect-sphinx-directives name: Check for incorrect Sphinx directives language: pygrep - entry: >- - \.\. (autosummary|contents|currentmodule|deprecated - |function|image|important|include|ipython|literalinclude - |math|module|note|raw|seealso|toctree|versionadded - |versionchanged|warning):[^:] + entry: | + (?x) + # Check for cases of e.g. .. warning: instead of .. warning:: + \.\.\ ( + autosummary|contents|currentmodule|deprecated| + function|image|important|include|ipython|literalinclude| + math|module|note|raw|seealso|toctree|versionadded| + versionchanged|warning + ):[^:] files: \.(py|pyx|rst)$ + - id: non-standard-imports + name: Check for non-standard imports + language: pygrep + entry: | + (?x) + # Check for imports from pandas.core.common instead of `import pandas.core.common as com` + from\ pandas\.core\.common\ import| + from\ pandas\.core\ import\ common| + + # Check for imports from collections.abc instead of `from collections import abc` + from\ collections\.abc\ import| + + from\ numpy\ import\ nan + types: [python] + - id: non-standard-imports-in-tests + name: Check for non-standard imports in test suite + language: pygrep + entry: | + (?x) + # Check for imports from pandas._testing instead of `import pandas._testing as tm` + from\ pandas\._testing\ import| + from\ pandas\ import\ _testing\ as\ tm| + + # No direct imports from conftest + conftest\ import| + import\ conftest + types: [python] + files: ^pandas/tests/ - id: incorrect-code-directives name: Check for incorrect code block or IPython directives language: pygrep diff --git a/ci/code_checks.sh b/ci/code_checks.sh index f01cd9ba014703..926e90f3dfa0ca 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -110,31 +110,6 @@ fi ### PATTERNS ### if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then - # Check for imports from pandas.core.common instead of `import pandas.core.common as com` - # Check for imports from collections.abc instead of `from collections import abc` - MSG='Check for non-standard imports' ; echo $MSG - invgrep -R --include="*.py*" -E "from pandas.core.common import" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from pandas.core import common" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from collections.abc import" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from numpy import nan" pandas - RET=$(($RET + $?)) ; echo $MSG "DONE" - - # Checks for test suite - # Check for imports from pandas._testing instead of `import pandas._testing as tm` - invgrep -R --include="*.py*" -E "from pandas._testing import" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "from pandas import _testing as tm" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - - # No direct imports from conftest - invgrep -R --include="*.py*" -E "conftest import" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - invgrep -R --include="*.py*" -E "import conftest" pandas/tests - RET=$(($RET + $?)) ; echo $MSG "DONE" - MSG='Check for use of exec' ; echo $MSG invgrep -R --include="*.py*" -E "[^a-zA-Z0-9_]exec\(" pandas RET=$(($RET + $?)) ; echo $MSG "DONE"