Skip to content

CI, STYLE Consolidate pygrep checks #40782

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 1 commit into from
Apr 5, 2021
Merged
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
75 changes: 31 additions & 44 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ repos:
entry: python scripts/check_for_inconsistent_pandas_namespace.py
language: python
types: [python]
- id: incorrect-code-directives
name: Check for incorrect code block or IPython directives
language: pygrep
entry: (\.\. code-block ::|\.\. ipython ::)
types_or: [python, cython, rst]
- id: no-os-remove
name: Check code for instances of os.remove
entry: os\.remove
Expand All @@ -106,49 +101,60 @@ repos:
pandas/tests/io/excel/test_writers\.py
|pandas/tests/io/pytables/common\.py
|pandas/tests/io/pytables/test_store\.py$
- id: non-standard-imports
name: Check for non-standard imports
- id: unwanted-patterns
name: Unwanted patterns
language: pygrep
entry: |
(?x)
# Check for imports from pandas.core.common instead of `import pandas.core.common as com`
from\ pandas\.core\.common\ import
# outdated annotation syntax, missing error codes
\#\ type:\ (?!ignore)
|\#\ type:\s?ignore(?!\[)

# foo._class__ instead of type(foo)
|\.__class__

# np.bool/np.object instead of np.bool_/np.object_
|np\.bool[^_8]
|np\.object[^_8]

# 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`
# imports from collections.abc instead of `from collections import abc`
|from\ collections\.abc\ import

# Numpy
|from\ numpy\ import\ random
|from\ numpy\.random\ import
types: [python]
- id: non-standard-imports-in-tests
name: Check for non-standard imports in test suite

# Incorrect code-block / IPython directives
|\.\.\ code-block\ ::
|\.\.\ ipython\ ::
types_or: [python, cython, rst]
exclude: ^doc/source/development/code_style\.rst # contains examples of patterns to avoid
- id: unwanted-patterns-in-tests
name: Unwanted patterns in tests
language: pygrep
entry: |
(?x)
# Check for imports from pandas._testing instead of `import pandas._testing as tm`
from\ pandas\._testing\ import
# pytest.xfail instead of pytest.mark.xfail
pytest\.xfail

# 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

# Check for use of pandas.testing instead of tm
# pandas.testing instead of tm
|pd\.testing\.

# Check for pd.api.types instead of from pandas.api.types import ...
# pd.api.types instead of from pandas.api.types import ...
|(pd|pandas)\.api\.types\.
types: [python]
files: ^pandas/tests/
- id: np-bool-and-np-object
name: Check for use of np.bool/np.object instead of np.bool_/np.object_
entry: |
(?x)
np\.bool[^_8]
|np\.object[^_8]
language: pygrep
types_or: [python, cython, rst]
- id: pip-to-conda
name: Generate pip dependency from conda
Expand All @@ -164,11 +170,6 @@ repos:
language: python
types: [rst]
files: ^doc/source/(development|reference)/
- id: type-not-class
name: Check for use of foo.__class__ instead of type(foo)
entry: \.__class__
language: pygrep
types_or: [python, cython]
- id: unwanted-patterns-bare-pytest-raises
name: Check for use of bare pytest raises
language: python
Expand All @@ -188,12 +189,6 @@ repos:
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module"
types: [python]
exclude: ^(asv_bench|pandas/tests|doc)/
- id: unwanted-patterns-pytest-xfail
name: Check for use of pytest.xfail
entry: pytest\.xfail
language: pygrep
types: [python]
files: ^pandas/tests/
- id: unwanted-patterns-strings-to-concatenate
name: Check for use of not concatenated strings
language: python
Expand All @@ -204,14 +199,6 @@ repos:
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace"
types_or: [python, cython]
- id: unwanted-typing
name: Check for outdated annotation syntax and missing error codes
entry: |
(?x)
\#\ type:\ (?!ignore)
|\#\ type:\s?ignore(?!\[)
language: pygrep
types: [python]
- id: use-pd_array-in-core
name: Import pandas.array as pd_array in core
language: python
Expand Down