Skip to content

Commit 1a056df

Browse files
author
MarcoGorelli
committed
Revert "STYLE use pandas-dev-flaker (pandas-dev#40906)"
This reverts commit 1f27ed0.
1 parent a28cadb commit 1a056df

15 files changed

+1497
-13
lines changed

.pre-commit-config.yaml

+93-3
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,9 @@ repos:
7070
rev: 6.0.0
7171
hooks:
7272
- id: flake8
73-
# Need to patch os.remove rule in pandas-dev-flaker
74-
exclude: ^ci/fix_wheels.py
7573
additional_dependencies: &flake8_dependencies
7674
- flake8==6.0.0
7775
- flake8-bugbear==22.7.1
78-
- pandas-dev-flaker==0.5.0
7976
- repo: https://github.com/pycqa/pylint
8077
rev: v2.15.6
8178
hooks:
@@ -184,6 +181,28 @@ repos:
184181
types: [rst]
185182
args: [--filename=*.rst]
186183
additional_dependencies: [flake8-rst==0.7.0, flake8==3.7.9]
184+
- id: frame-or-series-union
185+
name: Check for use of Union[Series, DataFrame] instead of FrameOrSeriesUnion alias
186+
entry: Union\[.*(Series,.*DataFrame|DataFrame,.*Series).*\]
187+
language: pygrep
188+
types: [python]
189+
exclude: ^pandas/_typing\.py$
190+
- id: inconsistent-namespace-usage
191+
name: 'Check for inconsistent use of pandas namespace'
192+
entry: python scripts/check_for_inconsistent_pandas_namespace.py
193+
language: python
194+
types: [python]
195+
- id: no-os-remove
196+
name: Check code for instances of os.remove
197+
entry: os\.remove
198+
language: pygrep
199+
types: [python]
200+
files: ^pandas/tests/
201+
exclude: |
202+
(?x)^
203+
pandas/tests/io/excel/test_writers\.py
204+
|pandas/tests/io/pytables/common\.py
205+
|pandas/tests/io/pytables/test_store\.py$
187206
- id: unwanted-patterns
188207
name: Unwanted patterns
189208
language: pygrep
@@ -193,6 +212,24 @@ repos:
193212
\#\ type:\ (?!ignore)
194213
|\#\ type:\s?ignore(?!\[)
195214
215+
# foo._class__ instead of type(foo)
216+
|\.__class__
217+
218+
# np.bool/np.object instead of np.bool_/np.object_
219+
|np\.bool[^_8]
220+
|np\.object[^_8]
221+
222+
# imports from pandas.core.common instead of `import pandas.core.common as com`
223+
|from\ pandas\.core\.common\ import
224+
|from\ pandas\.core\ import\ common
225+
226+
# imports from collections.abc instead of `from collections import abc`
227+
|from\ collections\.abc\ import
228+
229+
# Numpy
230+
|from\ numpy\ import\ random
231+
|from\ numpy\.random\ import
232+
196233
# Incorrect code-block / IPython directives
197234
|\.\.\ code-block\ ::
198235
|\.\.\ ipython\ ::
@@ -202,6 +239,7 @@ repos:
202239
# Check for deprecated messages without sphinx directive
203240
|(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)
204241
types_or: [python, cython, rst]
242+
exclude: ^doc/source/development/code_style\.rst # contains examples of patterns to avoid
205243
- id: cython-casting
206244
name: Check Cython casting is `<type>obj`, not `<type> obj`
207245
language: pygrep
@@ -232,6 +270,29 @@ repos:
232270
files: ^pandas/tests/extension/base
233271
types: [python]
234272
exclude: ^pandas/tests/extension/base/base\.py
273+
- id: unwanted-patterns-in-tests
274+
name: Unwanted patterns in tests
275+
language: pygrep
276+
entry: |
277+
(?x)
278+
# pytest.xfail instead of pytest.mark.xfail
279+
pytest\.xfail
280+
281+
# imports from pandas._testing instead of `import pandas._testing as tm`
282+
|from\ pandas\._testing\ import
283+
|from\ pandas\ import\ _testing\ as\ tm
284+
285+
# No direct imports from conftest
286+
|conftest\ import
287+
|import\ conftest
288+
289+
# pandas.testing instead of tm
290+
|pd\.testing\.
291+
292+
# pd.api.types instead of from pandas.api.types import ...
293+
|(pd|pandas)\.api\.types\.
294+
files: ^pandas/tests/
295+
types_or: [python, cython, rst]
235296
- id: pip-to-conda
236297
name: Generate pip dependency from conda
237298
language: python
@@ -252,6 +313,35 @@ repos:
252313
language: python
253314
types: [rst]
254315
files: ^doc/source/(development|reference)/
316+
- id: unwanted-patterns-bare-pytest-raises
317+
name: Check for use of bare pytest raises
318+
language: python
319+
entry: python scripts/validate_unwanted_patterns.py --validation-type="bare_pytest_raises"
320+
types: [python]
321+
files: ^pandas/tests/
322+
exclude: ^pandas/tests/extension/
323+
- id: unwanted-patterns-private-function-across-module
324+
name: Check for use of private functions across modules
325+
language: python
326+
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module"
327+
types: [python]
328+
exclude: ^(asv_bench|pandas/tests|doc)/
329+
- id: unwanted-patterns-private-import-across-module
330+
name: Check for import of private attributes across modules
331+
language: python
332+
entry: python scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module"
333+
types: [python]
334+
exclude: ^(asv_bench|pandas/tests|doc)/
335+
- id: unwanted-patterns-strings-to-concatenate
336+
name: Check for use of not concatenated strings
337+
language: python
338+
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate"
339+
types_or: [python, cython]
340+
- id: unwanted-patterns-strings-with-wrong-placed-whitespace
341+
name: Check for strings with wrong placed spaces
342+
language: python
343+
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace"
344+
types_or: [python, cython]
255345
- id: use-pd_array-in-core
256346
name: Import pandas.array as pd_array in core
257347
language: python

asv_bench/benchmarks/pandas_vb_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class BaseIO:
7070
def remove(self, f):
7171
"""Remove created files"""
7272
try:
73-
os.remove(f) # noqa: PDF008
73+
os.remove(f)
7474
except OSError:
7575
# On Windows, attempting to remove a file that is in use
7676
# causes an exception to be raised

ci/code_checks.sh

+69-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
#
99
# Usage:
1010
# $ ./ci/code_checks.sh # run all checks
11+
# $ ./ci/code_checks.sh lint # run linting only
12+
# $ ./ci/code_checks.sh patterns # check for patterns that should not exist
1113
# $ ./ci/code_checks.sh code # checks on imported code
1214
# $ ./ci/code_checks.sh doctests # run doctests
1315
# $ ./ci/code_checks.sh docstrings # validate docstring errors
1416
# $ ./ci/code_checks.sh single-docs # check single-page docs build warning-free
1517
# $ ./ci/code_checks.sh notebooks # check execution of documentation notebooks
1618

17-
[[ -z "$1" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "single-docs" || "$1" == "notebooks" ]] || \
18-
{ echo "Unknown command $1. Usage: $0 [code|doctests|docstrings|single-docs|notebooks]"; exit 9999; }
19+
[[ -z "$1" || "$1" == "lint" || "$1" == "patterns" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "single-docs" || "$1" == "notebooks" ]] || \
20+
{ echo "Unknown command $1. Usage: $0 [lint|patterns|code|doctests|docstrings|single-docs|notebooks]"; exit 9999; }
1921

2022
BASE_DIR="$(dirname $0)/.."
2123
RET=0
@@ -38,6 +40,71 @@ if [[ "$GITHUB_ACTIONS" == "true" ]]; then
3840
INVGREP_PREPEND="##[error]"
3941
fi
4042

43+
### LINTING ###
44+
if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
45+
46+
# Check that cython casting is of the form `<type>obj` as opposed to `<type> obj`;
47+
# it doesn't make a difference, but we want to be internally consistent.
48+
# Note: this grep pattern is (intended to be) equivalent to the python
49+
# regex r'(?<![ ->])> '
50+
MSG='Linting .pyx code for spacing conventions in casting' ; echo $MSG
51+
invgrep -r -E --include '*.pyx' --include '*.pxi.in' '[a-zA-Z0-9*]> ' pandas/_libs
52+
RET=$(($RET + $?)) ; echo $MSG "DONE"
53+
54+
# readability/casting: Warnings about C casting instead of C++ casting
55+
# runtime/int: Warnings about using C number types instead of C++ ones
56+
# build/include_subdir: Warnings about prefacing included header files with directory
57+
58+
fi
59+
60+
### PATTERNS ###
61+
if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
62+
63+
MSG='Check for use of exec' ; echo $MSG
64+
invgrep -R --include="*.py*" -E "[^a-zA-Z0-9_]exec\(" pandas
65+
RET=$(($RET + $?)) ; echo $MSG "DONE"
66+
67+
MSG='Check for pytest warns' ; echo $MSG
68+
invgrep -r -E --include '*.py' 'pytest\.warns' pandas/tests/
69+
RET=$(($RET + $?)) ; echo $MSG "DONE"
70+
71+
MSG='Check for pytest raises without context' ; echo $MSG
72+
invgrep -r -E --include '*.py' "[[:space:]] pytest.raises" pandas/tests/
73+
RET=$(($RET + $?)) ; echo $MSG "DONE"
74+
75+
MSG='Check for use of builtin filter function' ; echo $MSG
76+
invgrep -R --include="*.py" -P '(?<!def)[\(\s]filter\(' pandas
77+
RET=$(($RET + $?)) ; echo $MSG "DONE"
78+
79+
# Check for the following code in testing: `np.testing` and `np.array_equal`
80+
MSG='Check for invalid testing' ; echo $MSG
81+
invgrep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/
82+
RET=$(($RET + $?)) ; echo $MSG "DONE"
83+
84+
# Check for the following code in the extension array base tests: `tm.assert_frame_equal` and `tm.assert_series_equal`
85+
MSG='Check for invalid EA testing' ; echo $MSG
86+
invgrep -r -E --include '*.py' --exclude base.py 'tm.assert_(series|frame)_equal' pandas/tests/extension/base
87+
RET=$(($RET + $?)) ; echo $MSG "DONE"
88+
89+
MSG='Check for deprecated messages without sphinx directive' ; echo $MSG
90+
invgrep -R --include="*.py" --include="*.pyx" -E "(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)" pandas
91+
RET=$(($RET + $?)) ; echo $MSG "DONE"
92+
93+
MSG='Check for backticks incorrectly rendering because of missing spaces' ; echo $MSG
94+
invgrep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/
95+
RET=$(($RET + $?)) ; echo $MSG "DONE"
96+
97+
# Check for the following code in testing: `unittest.mock`, `mock.Mock()` or `mock.patch`
98+
MSG='Check that unittest.mock is not used (pytest builtin monkeypatch fixture should be used instead)' ; echo $MSG
99+
invgrep -r -E --include '*.py' '(unittest(\.| import )mock|mock\.Mock\(\)|mock\.patch)' pandas/tests/
100+
RET=$(($RET + $?)) ; echo $MSG "DONE"
101+
102+
MSG='Check for use of {foo!r} instead of {repr(foo)}' ; echo $MSG
103+
invgrep -R --include=*.{py,pyx} '!r}' pandas
104+
RET=$(($RET + $?)) ; echo $MSG "DONE"
105+
echo $MSG "DONE"
106+
fi
107+
41108
### CODE ###
42109
if [[ -z "$CHECK" || "$CHECK" == "code" ]]; then
43110

0 commit comments

Comments
 (0)