Skip to content

CI Move unwanted typing checks to pre-commit #37539

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 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,36 @@ repos:
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module"
types: [python]
exclude: ^(asv_bench|pandas/tests|doc)/
- id: FrameOrSeriesUnion
name: Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias
entry: Union\[.*(Series.*DataFrame|DataFrame.*Series).*\]
language: pygrep
types: [python]
exclude: ^pandas/_typing\.py$
- id: type-not-class
name: Check for use of foo.__class__ instead of type(foo)
entry: \.__class__
language: pygrep
files: \.(py|pyx)$
- id: unwanted-typing
name: Check for use of comment-based annotation syntax and missing error codes
entry: |
(?x)
\#\ type:\ (?!ignore)|
\#\ type:\s?ignore(?!\[)
language: pygrep
types: [python]
- id: no-os-remove
name: Check code for instances of os.remove
entry: os\.remove
language: pygrep
types: [python]
files: ^pandas/tests/
exclude: |
(?x)^
pandas/tests/io/excel/test_writers\.py|
pandas/tests/io/pytables/common\.py|
pandas/tests/io/pytables/test_store\.py$
- repo: https://github.com/asottile/yesqa
rev: v1.2.2
hooks:
Expand Down
23 changes: 0 additions & 23 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,6 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
RET=$(($RET + $?)) ; echo $MSG "DONE"

# -------------------------------------------------------------------------
# Type annotations

MSG='Check for use of comment-based annotation syntax' ; echo $MSG
invgrep -R --include="*.py" -P '# type: (?!ignore)' pandas
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check for missing error codes with # type: ignore' ; echo $MSG
invgrep -R --include="*.py" -P '# type:\s?ignore(?!\[)' pandas
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias' ; echo $MSG
invgrep -R --include="*.py" --exclude=_typing.py -E 'Union\[.*(Series.*DataFrame|DataFrame.*Series).*\]' pandas
RET=$(($RET + $?)) ; echo $MSG "DONE"

# -------------------------------------------------------------------------
MSG='Check for use of foo.__class__ instead of type(foo)' ; echo $MSG
invgrep -R --include=*.{py,pyx} '\.__class__' pandas
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check code for instances of os.remove' ; echo $MSG
invgrep -R --include="*.py*" --exclude "common.py" --exclude "test_writers.py" --exclude "test_store.py" -E "os\.remove" pandas/tests/
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Check for inconsistent use of pandas namespace in tests' ; echo $MSG
for class in "Series" "DataFrame" "Index" "MultiIndex" "Timestamp" "Timedelta" "TimedeltaIndex" "DatetimeIndex" "Categorical"; do
check_namespace ${class}
Expand Down
2 changes: 1 addition & 1 deletion scripts/validate_unwanted_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def main(

sys.exit(
main(
function=globals().get(args.validation_type), # type: ignore
function=globals().get(args.validation_type),
source_path=args.paths,
output_format=args.format,
)
Expand Down